VikiC Posted November 13, 2010 Share Posted November 13, 2010 Hi I'm having a bit of bother with my login. I created a login using this tutorial http://www.phpeasystep.com/phptu/6.html and it works perfectly. So i have attempted to change it to meet my own database. So basically i've changed the database, table names etc to meet my own. I haven't changed any other lines. When i run it i get an error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26 The code is below: <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="final year project"; // Database name $tbl_name="tbl_user"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $mem_username=$_POST['mem_username']; $mem_password=$_POST['mem_password']; // To protect MySQL injection (more detail about MySQL injection) $mem_username = stripslashes($mem_username); $mem_password = stripslashes($mem_password); $mem_username = mysql_real_escape_string($mem_username); $mem_password = mysql_real_escape_string($mem_password); $sql="SELECT * FROM $tbl_name WHERE username='$mem_username' and password='$mem_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $mem_username and $mem_password, table row must be 1 row if($count==1){ // Register $mem_username, $mem_password and redirect to file "login_success.php" session_register("mem_username"); session_register("mem_password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Line 26 is $count=mysql_num_rows($result); I'm baffled as to why the test database worked. I tried another test database but got the same error. baffled.com Hope someone can help MOD EDIT: . . . tags added. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2010 Share Posted November 13, 2010 Use mysql_error after your query to check for errors Echo you sql string to insure it is what it's supposed to be Quote Link to comment Share on other sites More sharing options...
VikiC Posted November 13, 2010 Author Share Posted November 13, 2010 I now get: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26 Fatal error: SQL: SELECT * FROM tbl_user WHERE username='' and password='', Error: Unknown column 'username' in 'where clause' in C:\xampp\htdocs\checklogin.php on line 26 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 13, 2010 Share Posted November 13, 2010 breakin' it down.... Fatal error: SQL: SELECT * FROM tbl_user WHERE username='' and password='', Error: Unknown column 'username' in 'where clause' in C:\xampp\htdocs\checklogin.php on line 26 SQL: SELECT * FROM tbl_user WHERE username='' and password='' Error: Unknown column 'username' in 'where clause' Unknown column 'username' Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2010 Share Posted November 13, 2010 Unfortunately, that tutorial sucks. It's outdated, uses deprecated functions, and makes the assumption that magic_quotes_gpc = On without even testing for it. It appears to be written for PHP 4. Forget most of what you learned from it, post your form here, and I'll have a look at what's happening. Quote Link to comment Share on other sites More sharing options...
VikiC Posted November 13, 2010 Author Share Posted November 13, 2010 Got it working guys thanks. 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.