/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Loging users in

OK, I wrote these 2 functions

[code=php]
function db_connect()
{
// connect to the database using the variables
// $dbhost, $dbuser, $dbpass, $dbname

$dbhost=’localhost’;
$dbuser=’test’;
$dbpass=’test’;
$dbname=’test’;

$db_connect=mysql_connect($dbhost, $dbuser, $dbpass);
if(!$db_connect)
{
echo “Could not connect to DB”;
}

else{
mysql_select_db($dbname, $db_connect);
}
}

function get_user_information($email, $password){
//function will be used to check if the
//information suplied by the user in the login page is correct

db_connect();

$query = mysql_query(‘SELECT * FROM user WHERE user_email=”‘.$email.'” and user_password=”‘.$password.'”;’);

$user_details=mysql_fetch_array($query);
return $user_details;

}
[/code]

Bu the second function always returns a false result, although I am positiove I am supplying the correct email and password.

Any ideas why might it be?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@monarch_684Sep 03.2008 — Try this:

[code=php]$query = mysql_query('SELECT * FROM user WHERE user_email='$email' and user_password='$password';'); [/code]
Copy linkTweet thisAlerts:
@NightcatauthorSep 03.2008 — That didn't work and I tried all sorts of variations ?

I'll keep on trying different things though ?
Copy linkTweet thisAlerts:
@monarch_684Sep 03.2008 — Try this I know this works:

[code=php]<<<<<<<*******Log In Page*******>>>>>>>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!--
Author: Joseph Monarch
-->
<title></title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
<meta name="robots" content="noindex, nofollow" />
<link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>
<div id="wrapper">
<h1>Admin Access</h1>
<form method="post" action="process.php">
<p>Username<br /><input type="text" name="username" /></p>
<p>Password<br /><input type="password" name="password" /></p>
<p><input type="submit" value="Log In" /><input type="reset" value="Cancel" /></p>
</form>
</div>
</body>
</html>



<<<<<<<*******Log In Process Page*******>>>>>>>
<?php
session_start();
$uname = $_POST["username"];
$pwd = $_POST["password"];
$_SESSION['uname'] = $uname;
$_SESSION['pwd'] = $pwd;

$connection = mysql_connect("DB Host", "username", "password");
@mysql_select_db("DB Name", $connection) or die( "Unable to select database" . mysql_error());

$query = "SELECT * FROM tablename";
$result = mysql_query($query)
or die ("Couldn't query data" . mysql_error());

$row = mysql_fetch_assoc($result);

if($row['username'] != $uname)
echo "<p>Invalid Username!</p>";
else {
$query = "SELECT * FROM tablename WHERE username = '$uname'";
$result = mysql_query($query)
or die ("Couldn't query data" . mysql_error());

$row = mysql_fetch_assoc($result);

if($row['password'] != $pwd){
echo "<p>Password and Username do not match!</p>";
echo $row['password'];}
else if($pwd == 'password')
header('Location: pwdchange.php');
else
header('Location: admin.php');
}
?>



<<<<<<<*******Check Log In*******>>>>>>>
<?php
session_start();

$pwd = $_SESSION['pwd'];
$uname = $_SESSION['uname'];

$connection = mysql_connect("DB Host", "username", "password");
@mysql_select_db("DB Name", $connection) or die( "Unable to select database" . mysql_error());

$query = "SELECT * FROM tablename";
$result = mysql_query($query)
or die ("Couldn't query data" . mysql_error());

$row = mysql_fetch_assoc($result);

if($row['username'] != $uname)
echo "<p>You must be logged in. Log in <a href='index.php'>here.</a></p>";
else {
$query = "SELECT * FROM tablename WHERE username = '$uname'";
$result = mysql_query($query)
or die ("Couldn't query data" . mysql_error());

$row = mysql_fetch_assoc($result);

if($row['password'] != $pwd)
echo "<p>You be logged in. Log in <a href='index.php'>here.</a></p>";
else {
/* Start Page Code
.
.
.
?>
[/code]
Copy linkTweet thisAlerts:
@chazzySep 03.2008 — replace this line

[code=php]
$query = mysql_query('SELECT * FROM user WHERE user_email="'.$email.'" and user_password="'.$password.'";');
[/code]


With
[code=php]
$query = mysql_query("SELECT * FROM user WHERE user_email='".$email."' and user_password='".$password."';");
[/code]
Copy linkTweet thisAlerts:
@NightcatauthorSep 03.2008 — OK I nailed the problem.

The "get_user_information()" does not pass down the variable.
×

Success!

Help @Nightcat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...