PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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 .....
}
}
}
}
if(isset($_POST['user_id'])) {
$user = new stdClass;
$user->id = mysql_real_escape_string($_POST['user_id']);
$user->idQuery = mysql_query("SELECT `id` FROM `user` WHERE `id` ='{$user->id}'")
or die(mysql_error());
// If the user was found,
if(mysql_num_rows($result) < 1)
throw new Exception("Your Account number was NOT found in our database!");
else {
$name = mysql_real_escape_string($_SESSION['name']);
$user->usernameQuery = mysql_query("SELECT `id` FROM `user` WHERE `username` = '$name'")
or die("Couldn't execute query for collecting your data.");
if(mysql_num_rows($user->usernameQuery) < 1)
throw new Exception("Sorry your inserted Account no. Does Not match with your username");
else
throw new Exception("Sorry your inserted Account no. Does Not match with your username");
}
}
There is my rendition, quickly compiled so I apologize for any errors but they should be minute. You should remain somewhat consistent in your sql query calls however I did use your calls.