ManOnScooter Posted November 20, 2007 Share Posted November 20, 2007 I know this dumb, but just cant get thru.. can anybody see any mistake in the code here?? <?php mysql_connect("localhost", "root", "administrator") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $password = sha1($_POST['password']); $result = mysql_query("SELECT * FROM userlogin WHERE username='$_POST['username']' and passwordHash='$password'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['username']; ?> name of my table-userlogin my table is as follows username passwordHash test1 b444ac06613fc8d63795be9ad0beaf55011936ac test 9bc34549d565d9505b287de0cd20ac77be1d3f2c <html> <body> <form action="2.php" method="post"> username: <input type="text" name="username" /> password: <input type="password" name="password" /> <input type="submit" /> </form> </body> </html> what is interesting is that the IE gives error as http 500 internal server error & firefox says Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\2.php on line 7 Ok i know this is really a dumb question-anybody can give any help? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 20, 2007 Share Posted November 20, 2007 Your query may not be properly formatted in the string. You have the array value (with single quotes) within a set of single quotes. Try this: $query = "SELECT * FROM userlogin WHERE username='".$_POST['username']."' and passwordHash='$password'"; $result = mysql_query($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
ManOnScooter Posted November 20, 2007 Author Share Posted November 20, 2007 Thanx MJ that did work, but how do I know where i need to try username='".$_POST['username']."' and where to try $result = mysql_query("SELECT * FROM userlogin WHERE username='$_POST['username']' and passwordHash='$password'") or die(mysql_error()); or was it the magic done with putting the query seperately..?? ManOnScooter Thanx MJDamo.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 20, 2007 Share Posted November 20, 2007 The problem was not that the query was not separated out. The problem was using the array value within the double quotes. The array value (with the brackets) is not interpreted correctly within double quotes. Personally I always create my queries as strings variables and then use that variable to run the query. It makes debugging MUCH easier. For example, you can print the queery to the page if there is an error to verify the query was properly formatted. $result = mysql_query($query) or die ("The error:<br>". mysql_error() . "<br>occured with the query:<br>".$query); Quote Link to comment 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.