shatteredcode Posted May 26, 2008 Share Posted May 26, 2008 I'm trying to set up a login script with the users coming form a database. I can't, however, seem to extract that information. What's wrong with my script? <?php INCLUDE "connect.php"; $host = "host"; $database = "database"; $user = "user"; // I changed these for the post, they're right in my script $pass = "pass"; ConnectToDatabase($database, $user, $pass, $host); /**********/ //Select our table. $query = "SELECT user, pass FROM users"; //Query the table (Get the information from it.) $result = mysql_query($query); //Extracts the array from the table $row = mysql_fetch_array($result); $database_user == $row['user']; echo ($database_user); print "hello, why don't you login? <br />"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> </head> <body> <form id="login" name="login" method="post" action="login.php"> <label> User <input type="text" name="user" id="user" /> </label> <p> Password <input type="password" name="pass" id = "pass" /> </p> <input type="submit" id="submit" name="sumbit" /> </form> </body> </html> <?php if ($typed_user == $database_user) { echo('Worked!'); } else { echo(' Didn\'t Work!'); } ?> I'm not sure of my error. BTW: I'm only checking the user right now, not the password. This is just a test. Thanks. Quote Link to comment Share on other sites More sharing options...
jscix Posted May 26, 2008 Share Posted May 26, 2008 <?php INCLUDE "connect.php"; $host = "host"; $database = "database"; $user = "user"; // I changed these for the post, they're right in my script $pass = "pass"; ConnectToDatabase($database, $user, $pass, $host); $query = "SELECT user, pass FROM users WHERE `user` = '$typed_user'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $database_user == $row['user']; echo($database_user); print "hello, why don't you login? <br />"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> </head> <body> <form id="login" name="login" method="post" action="login.php"> <label> User <input type="text" name="user" id="user" /> </label> <p> Password <input type="password" name="pass" id = "pass" /> </p> <input type="submit" id="submit" name="sumbit" /> </form> </body> </html> <?php if ($typed_user == $database_user) { echo('Worked!'); } else { echo(' Didn\'t Work!'); } ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted May 26, 2008 Share Posted May 26, 2008 $query = "SELECT user, pass FROM users WHERE `user` = '$typed_user'"; $typed_user has not been defined. You need to get it from the posted data. $database_user == $row['user']; to assign a value, use "=" and not the comparison operator "==" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.