Ducky1 Posted March 18, 2009 Share Posted March 18, 2009 Hey guys, Im trying to create a simple login script that checks a username against an SQL database, and then compares the replied password with the password entered. Right now its compiling, but not returning an answer. Thanks for your help in advance. <?php $pass = $_POST['passwd']; $user = $_POST['login']; //echo $pass . $user; $conn = mysql_connect("*", "*", "*"); if (!$conn ) { echo "ERROR: Could not connect to the database."; } $did_we_find_a_db_to_use = mysql_select_db("*"); if (!$did_we_find_a_db_to_use) { echo "ERROR: Invalid database name."; } $data = mysql_query("SELECT * FROM users WHERE 'name' = " . $user . ";"); while($info = mysql_fetch_array( $data )) { if($info['pass']==$pass) { echo "Correct"; } else { echo "Wrong"; } } ?> Link to comment https://forums.phpfreaks.com/topic/149947-php-mysql-login-type-issue/ Share on other sites More sharing options...
hellonoko Posted March 18, 2009 Share Posted March 18, 2009 Well.... I am pretty sure you query is bad. $data = mysql_query("SELECT * FROM users WHERE 'name' = " . $user . ";"); Should be: mysql_query("SELECT * FROM users WHERE name = $user") Here is example query from a page of mine: $query = "SELECT rank FROM ideas WHERE id=$delete_idea" or die (mysql_error()); The OR DIE is good will show you if mysql is messing up. You could also put: error_reporting(E_ALL); At the top of your page to force it to report every tiny error. Link to comment https://forums.phpfreaks.com/topic/149947-php-mysql-login-type-issue/#findComment-787526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.