Jump to content

errors with passing variables


bbram

Recommended Posts

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";
}*/
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.