selbekk Posted April 16, 2008 Share Posted April 16, 2008 hey again... i have a problem logging in with my new log in script... i get the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kristof3/public_html/tempwork/login.php on line 24 Wrong Username or Password. Try again. this is my code: <?php /* Script that handles the login procedure. Gets info from login-form.php */ include_once("mysql-connect.php"); // Include the connection info for the MySQL-database // Makes variables for the user info. $username = $_POST['user']; $password = $_POST['pass']; // Protection against MySQL insertion (security measure) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // Encrypts the password $password = md5($password); // Making a query to the database $sql = "SELECT * FROM login WHERE username='$username' AND password='$password'"; $result = mysql_query($sql); // Checking if there is a match, and only one match $count = mysql_num_rows($result); if ($count == 1) { // session_register("username"); session_register("password"); header("location:index.php?login=good"); } else echo "Wrong Username or Password. <a href='index.php?page=login-form'>Try again.</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/101429-solved-login-script-problems/ Share on other sites More sharing options...
p2grace Posted April 16, 2008 Share Posted April 16, 2008 Try using complete syntax in your query, also you should always verify the query works before continuing: <?php /* Script that handles the login procedure. Gets info from login-form.php */ include_once("mysql-connect.php"); // Include the connection info for the MySQL-database // Makes variables for the user info. $username = $_POST['user']; $password = $_POST['pass']; // Protection against MySQL insertion (security measure) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // Encrypts the password $password = md5($password); // Making a query to the database $sql = "SELECT * FROM `login` WHERE `username` = '$username' AND `password` = '$password'"; $result = mysql_query($sql); if(!$result){ die("Unable to connect to database. ".mysql_error()); } // Checking if there is a match, and only one match $count = mysql_num_rows($result); if ($count == 1) { // session_register("username"); session_register("password"); header("location:index.php?login=good"); } else echo "Wrong Username or Password. <a href='index.php?page=login-form'>Try again.</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/101429-solved-login-script-problems/#findComment-518853 Share on other sites More sharing options...
selbekk Posted April 16, 2008 Author Share Posted April 16, 2008 thanks for your time, but it was just a stupid typ-o.. the table´s column was called user instead of username. but thanks =) Link to comment https://forums.phpfreaks.com/topic/101429-solved-login-script-problems/#findComment-518860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.