MySQL and MD5 password with PHP...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mateoc15
Forum Newbie
Posts: 3
Joined: Sat Mar 27, 2004 12:07 am

MySQL and MD5 password with PHP...

Post 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;
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Re: MySQL and MD5 password with PHP...

Post 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:
mateoc15
Forum Newbie
Posts: 3
Joined: Sat Mar 27, 2004 12:07 am

Post 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 :)
Last edited by mateoc15 on Sat Mar 27, 2004 12:23 am, edited 1 time in total.
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post 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>"; 
?>
mateoc15
Forum Newbie
Posts: 3
Joined: Sat Mar 27, 2004 12:07 am

Post by mateoc15 »

see how quickly i edited my post to not look any dumber than i already do? hehe :oops:
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

It happens to the best right? :wink:

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