Forum Moderators: open
I have 3 php files one named index.php (which is the login page)
2nd file - checklogin.php
3rd file - login_success.php
I believe the index.php is fine I have a form that its action is set to checklogin.php
Here is what I have for the checklogin.php page
<?php
$host="localhost"; // Host name
$username="lpusername_username"; // Mysql username
$password="password"; // Mysql password
$db_name="lpusername_siteusers"; // Database name
$tbl_name="web_members"; // Table name // Connect to server and select database.
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
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
?>
then my html stuff
I have set up a user and when I click on submit it goes to the checklogin.php and I get this error at the top of the page:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mylpusername/public_html/checklogin.php on line 26
So what am I doing wrong?
you should first test if $result is FALSE and if so check the error that was returned.