help with code
Posted: Sat Nov 01, 2008 1:13 am
Hi All
Can someone please help me with this query, 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 query below I’m getting error message both times whether he inserts Right or Wrong Acc no. Some help will be greatly appreciated.
Thanks Zed 
Can someone please help me with this query, 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 query below I’m getting error message both times whether he inserts Right or Wrong Acc no. Some help will be greatly appreciated.
Code: Select all
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 .....
}
}
}
}