bbram Posted January 8, 2011 Share Posted January 8, 2011 Hello I am getting the following errors when I am running the code below. I am not 100% for sure what the error's mean. If possible can you guide help to figure out what is wrong with my code? Notice: Undefined index: Userid in C:\wamp\www\checklogin.php on line 13 Notice: Undefined index: password in C:\wamp\www\checklogin.php on line 14 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\checklogin.php on line 26 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\checklogin.php on line 29 <?php $host="localhost"; $username="root"; $password=""; $db_name="movedb"; $tbl_name="security"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("Cannot Select Database"); // username and password sent from form $myusername=$_POST['Userid']; $mypassword=$_POST['password']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); //this creates an array with the results $row= mysql_fetch_array($result); echo ("HI"); //this gets the value held in the 'user_level' column for the user //$user_level = $row['user_level']; if($count==1) { echo ("passed"); echo $myusername; echo $mypassword; /* // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword");*/ header("location:login_success.php"); } else { echo ("failed"); echo $myusername; echo $mypassword; //header("location:access_denied.php"); } /*else { echo "Wrong Username or Password"; }*/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/223784-errors-with-passing-variables/ Share on other sites More sharing options...
tomtimms Posted January 9, 2011 Share Posted January 9, 2011 Need to find out why your query isn't working, after this line $result=mysql_query($sql); use mysql_error(); and your query error will display on the page. From there we can see what the problem is.... Also try and use if(isset($_POST['Userid']){$myusername=$_POST['Userid'];} else {$myusername = "Not Set";} and echo out $myusername to see if you are even getting the passed variable in the URL. Quote Link to comment https://forums.phpfreaks.com/topic/223784-errors-with-passing-variables/#findComment-1157201 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.