beennn Posted July 22, 2012 Share Posted July 22, 2012 (edited) 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 July 22, 2012 by beennn Link to comment Share on other sites More sharing options...
Don E Posted July 22, 2012 Share Posted July 22, 2012 What's your HTML form look like that submits to the script above? Make sure the name attribute for the input element for the username is the same as $_POST['username']; Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2012 Author Share Posted July 22, 2012 Oh ok, so the scripts fine just there cant be a difference between method of posting? The alternative to $_POST['username']; would be $_POST["username"]; ? Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 22, 2012 Share Posted July 22, 2012 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 More sharing options...
Don E Posted July 22, 2012 Share Posted July 22, 2012 (edited) 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 July 22, 2012 by Don E Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2012 Author Share Posted July 22, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now