Trouble with mysql_query and database

int checkPass ( string $user , string $password )
Write a PHP function “checkPass” that takes two arguments: $user and $password and returns the UserID if the password matches the MD5 encoding of the appropriate password in the interview_user_info table below and -1 otherwise.

The $user variable contains the NetID of the individual; the $password variable contains a clear-text version of the password as submitted.

±--------------------------------------------------------------------------------+
| interview_user_info |
±----------±------------±----------±-------±---------------------------------+
| UserID | LastName | FirstName | NetID | Passwd |
±----------±------------±----------±-------±---------------------------------+
| 469562029 | Gonzalez | Shauntee | sgonz | 530b4a0ae65148d112537bc0eafba9c9 |
| 702930431 | Bates | Austin | abates | 9cdfb439c7876e703e307864c9167a15 |
±----------±------------±----------±-------±---------------------------------+
The connection and database selection are taken care of. Write the query to pull data from the table “interview_user_info”, and return the result. The connection will be closed for you.

Hint: You will likely need to make use of the following functions and possibly others: md5, mysql_query, mysql_fetch_assoc

Code Editor

Ive been bouncing around so many times but I jst cant seem to get anything to work. Here is what I currently have but it has changed a lot.

<? function checkPass($user, $passord) { $query = "SELECT Passwd FROM interview_user_info WHERE NetID = '$user'"; $result = mysql_query($query); $passwordArr['Passwrd'] = mysql_fetch_assoc($result); $passTest = md5($password); $query2 = "SELECT UserID FROM interview_user_info WHERE NetID = '$user'"; $result2 = mysql_query($query2); $userIDArr['UserID'] = mysql_fetch_assoc($result2); //print_r(array_values($userIDArr)); //print_r(current($userIDArr)); return $result; } ?>
Hello Justin, i have seen that query used by you in function are wrong. Replace $query = "SELECT Passwd FROM interview_user_info WHERE NetID = '$user'"; with below code [php] //Use this query $query = "SELECT Passwd FROM interview_user_info WHERE NetID = '".$user."'"; [/php] And also replace $query2 = "SELECT UserID FROM interview_user_info WHERE NetID = '$user'"; with below code [php] //use this query $query2 = "SELECT UserID FROM interview_user_info WHERE NetID = '".$user."'"; [/php]

I hope this will helpful for you
Reply your feed back
SR

Input Expected Answer Your Answer
NetID: baduser -1 Resource id #6
NetID: sgonz 469562029 Resource id #8
NetID: abates 702930431 Resource id #10
NetID: jkirk 457619494 Resource id #12
NetID: colson 737279745 Resource id #14
NetID: saluru 492125459 Resource id #16
NetID: badpass -1 Resource id #18

So I changed what you suggested and it did something better haha but still is in the memory as resource id numbers and I need it to send the UserID of each person

Hello Jstnlng, use below function instead of currently used function [php] #use below function function checkPass($user, $password) { $sql="SELECT * FROM interview_user_info WHERE NetID = '".$user."'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if(!empty($row)) { if(md5($password) == $row["Passwd"]) $val = $row["UserID"]; else $val = '-1'; } else { $val = '-1'; } return $val; } [/php]

i have used following database table structure
UserID LastName FirstName NetID Passwd
469562029 Gonzalez Shauntee sgonz 2326c8209f06fd2495fadf28edfc22f8

Note: Detail i have checked by me
user name : sgonz
password : kt123

I hope your looking for something like this
Reply your Feedback
SR

That worked perfectly. Thank you very much you were very helpful. I know java and C and some HTML so I’m just starting to do some PHP stuff and I really enjoy it but it can be frustrating some times haha. Thanks again though.

Hello Jstnlng, It's really nice to see that finally your problem is solved. For any other issue or problem ask fell free and post your problem here. Enjoy... :) :) ~~SR~~
Sponsor our Newsletter | Privacy Policy | Terms of Service