Jump to content

[SOLVED] login and password hashing help


ManOnScooter

Recommended Posts

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?

Link to comment
Share on other sites

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());  

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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);

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.