User014019 User014019 - 6 months ago 23
SQL Question

$_POST not inserting values in the database

I have a form. When the user submits, the values should insert in the database. Only the value of one $_POST is not inserted in the database, but the other $_POST's are inserting properly.

How to fix this?

HTML:

<input type="text" name="position" value="<?php echo $_POST['jobTitle']; ?>" id="position" required/>


PHP snippet:

$firstName = $middleName = $lastName = $email = $mobile = $resume = $position = $message = $attachment_id = $locations = "";

if(isset($_POST['submit'])){
$firstName = isset($_POST['firstName']) ? $_POST['firstName'] : '';
$middleName = isset($_POST['middleName']) ? $_POST['middleName'] : '';
$lastName = isset($_POST['lastName']) ? $_POST['lastName'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$mobile = isset($_POST['mobile']) ? $_POST['mobile'] : '';
$locations = isset($_POST['locations_list']) ? $_POST['locations_list'] : '';
$position = isset($_POST['jobTitle']) ? $_POST['jobTitle'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
if( ! empty($_FILES)){
$file=$_FILES['resumeFile'];
$attachment_id = upload_user_file($file);
}

$sql=$wpdb->query("INSERT INTO resume_databank(submit_time,last_name,first_name,middle_name,mobile_number,email,location,position,message,process_resume,attachment_resume_id) VALUES (now(),'$lastName','$firstName','$middleName','$mobile','$email','$locations','$position','$message','No','$attachment_id')");
}

exit();

Answer

Change this part

$position = isset($_POST['jobTitle']) ? $_POST['jobTitle'] : '';

to

$position = isset($_POST['position']) ? $_POST['position'] : '';

because in your form. your field name is position and $_POST['jobTitle']; is just a value

Comments