Jump to content

Help finding error in small script


beennn

Recommended Posts

Could use a hand finding what i've done wrong in this script Script:

<?phpmysql_connect('####', '####', '####') or die('Could not connect: ' . mysql_error());mysql_select_db('####') or die('Could not select database'); $username = $_POST['username'];$password = $_POST['password'];$sql="SELECT * FROM 'accounts' WHERE username='$username' and password='$password'";$result=mysql_query($sql); $count=mysql_num_rows($result);   if($count==1){   echo "Login successful";    } else {     echo "Login failed";     }?>

Error:

( ! ) Notice: Undefined index: username in C:\wamp\www\_#\display.php on line 5Call Stack# Time Memory Function Location1 0.0003 676216 {main}( ) ..\display.php:0( ! ) Notice: Undefined index: password in C:\wamp\www\_#\display.php on line 6Call Stack# Time Memory Function Location1 0.0003 676216 {main}( ) ..\display.php:0( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\_#\display.php on line 11Call Stack# Time Memory Function Location1 0.0003 676216 {main}( ) ..\display.php:02 0.0116 683696 mysql_num_rows ( ) ..\display.php:11Login failed

Edited by beennn
Link to comment
Share on other sites

it depends on your form name, like say if you have a field looking like this <input type"text" name"krazzz" /> then the $_POST[] ill be $_POST['krazzz']

Link to comment
Share on other sites

Using single quotes or double is the same thing basically with the above; no difference. Undefined index means there is nothing in the super global $_POST array with an index named username which could be from the username input name attribute of the form that is submitting to the above script is not identical to: $_POST['username']; So for example, if you have this in your form: Username:<input type"text" name"usrname" /> and then have this: $_POST['username']; in your PHP script, you're going to get the Undefined index error. That is why I asked what your HTML form looks like.

Edited by Don E
Link to comment
Share on other sites

Oh ok, thank you both. I would have posted but im not using html for posting lol. In the process of setting up a login checker inside of unity. Wanted to know where I was going wrong, looks like i've gone wrong in unity. Thanks for the help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...