Forum Moderators: coopster

Message Too Old, No Replies

help verifying correct number was inserted

         

zed420

5:51 pm on Nov 1, 2008 (gmt 0)

10+ Year Member



Hi All
Can someone please help me with this code, there are two MySQL tables ‘user_tb’ and ‘job_tb’ id is the primary key in user_tb and user_id is the foreign key in job_tb. A user populates the user_id by form as his Acc no. All I’m trying to do is to prevent him inserting the wrong Acc no (user_id) if he does an error message pop up. With code below I’m getting error message both times whether he inserts Right or Wrong Acc no. Some help will be greatly appreciated.

if (isset($_POST['user_id'])) {
$user_id= mysql_real_escape_string($_POST['user_id']);
$query = "SELECT id FROM user WHERE id ='$user_id'";
$result = mysql_query($query)or die(mysql_error());
// If the user was found,
if (mysql_num_rows($result) < 1) {
error_message("Your Account number was NOT found in our database!");
}else{
if ($name = $_SESSION['name']){
$query = "SELECT id FROM user WHERE username = '$name'";
$result = mysql_query($query)
or die ("Couldn't execute query for collecting your data.");
if (mysql_num_rows($result) != 'user_id') {
error_message("Sorry your inserted Account no. Does Not match with your username");
}else{
Query= INSERT .....
}
}
}
}
Thanks
Zed

jatar_k

12:29 pm on Nov 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld zed420,

your comparison is messed up

if (mysql_num_rows($result) != 'user_id') {

I can guarantee that the int returned from mysql_num_rows will never be the same as the string 'user_id'

I am guessing you meant to have some other comparison there

zed420

9:00 am on Nov 3, 2008 (gmt 0)

10+ Year Member



Thanks you were right it should've been like this;
if (mysql_num_rows($result,0) != 'user_id') {

Thanks
Zed