Page 1 of 1

MySQL and MD5 password with PHP...

Posted: Sat Mar 27, 2004 12:07 am
by mateoc15
I have created a basic user table in my database, have no problems with connecting, etc... but when I run my script to enter an MD5 encrypted password into my table, it doesn't appear when I go back to view the record in the table... doesn't give me any kind of error either.

I have checked to make sure that the UserPass field is long enough (varchar 40) to hold the encrypted password... Can't figure out what's up... any ideas? Here are the two code snips I am using for testing:

FIRST, THE DATA ENTRY TO THE DATABASE (can be viewed at http://www.badapplebiz.com/beta/setmypw.php):

$md5pw = md5("password");
$query = "UPDATE Users SET UserPass = $md5pw WHERE UserID = 123";
$results = mysql_query($query);
echo $md5pw . " entered into password field.";


THEN THE VIEWING OF THE EXISTING RECORDS IN THE TABLE (can be viewed at http://www.badapplebiz.com/beta/try.php):

$query = "SELECT * FROM Users";
$result = mysql_query($query);

echo "<table><tr><td>UserID</td><td>UserName</td><td>UserPass</td><td>UserFName</td><td>UserLName</td><td>UserEmail</td></tr>";
while ($array = mysql_fetch_assoc($result))
{
echo "<tr><td>$array[UserID]</td><td>$array[UserName]</td><td>$array[UserPW]</td>
<td>$array[UserFName]</td><td>$array[UserLName]</td><td>$array[UserEmail]</td></tr>";
}
echo "</table>";

mysql_free_result($result);
exit;

Re: MySQL and MD5 password with PHP...

Posted: Sat Mar 27, 2004 12:13 am
by Goowe
mateoc15 wrote: $query = "UPDATE Users SET UserPass = $md5pw WHERE UserID = 123";
Here you set UserPass = $md5pw
mateoc15 wrote: echo "<table><tr><td>UserID</td><td>UserName</td><td>UserPass</td><td>UserFName</td><td>UserLName</td><td>UserEmail</td></tr>";
while ($array = mysql_fetch_assoc($result))
{
echo "<tr><td>$array[UserID]</td><td>$array[UserName]</td><td>$array[UserPW]</td>
<td>$array[UserFName]</td><td>$array[UserLName]</td><td>$array[UserEmail]</td></tr>";
}
echo "</table>";
Here you're using $array[UserPW]. Before you called the password yielding column "UserPass" while here you call it "UserPW." Also, I believe that the correct syntax would be $array['UserPW'] (or $array['UserPass'])

/Edit... I might stand corrected, $array[UserPW] might be correct... seen as it is working on y our test site? :wink:

Posted: Sat Mar 27, 2004 12:21 am
by mateoc15
Wow... I feel really dumb now. Sometimes it just takes someone else looking at your code to figure out that you're really an idiot. Thanks Goowe :)

Posted: Sat Mar 27, 2004 12:23 am
by Goowe
Ahh, it's not where you set the row information but where you pull it out :wink:

You said the password column was titled "UserPass" when you set it? When you try and pull out the information you used the coumn "UserPW"... try

Code: Select all

<?php
echo "<table><tr><td>UserID</td><td>UserName</td><td>UserPass</td><td>UserFName</td><td>UserLName</td><td>UserEmail</td></tr>";
while ($array = mysql_fetch_assoc($result))
{
echo "<tr><td>$array[UserID]</td><td>$array[UserName]</td><td>$array[UserPass]</td>
<td>$array[UserFName]</td><td>$array[UserLName]</td><td>$array[UserEmail]</td></tr>";
}
echo "</table>"; 
?>

Posted: Sat Mar 27, 2004 12:26 am
by mateoc15
see how quickly i edited my post to not look any dumber than i already do? hehe :oops:

Posted: Sat Mar 27, 2004 12:27 am
by Goowe
It happens to the best right? :wink:

Hope it worked for you... g'luck!