Reputation: 209
Below is a PDO update query, however I keep getting these errors:
array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
I have recently switched to using PDO so don't be to mean. after searching these errors I found very little issue with the query therefore am at a loss to see why these errors are coming up.
<?php
error_reporting(E_ALL); ini_set("display_errors", 1);
if(isset($_POST["update_data"])){
// connect to the database
$servername = 'HOST';
$username = 'USER';
$password = 'PASS';
$dbname = 'TABLE';
$current_user = $_SESSION['user_name'];
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE table SET
user_name = :user_name,
user_email = :user_email,
user_phone = :user_phone,
user_gender = :user_gender,
employment_status = :employment_status,
user_min_salary = :user_min_salary,
user_dob = :user_dob,
user_location = :user_location,
user_years_experience = :user_years_experience,
job_title = :job_title,
company_name = :company_name,
user_responsibilities = :user_responsibilities,
job_duration = :job_duration,
job_title_two = :job_title_two,
company_name_two = :company_name_two,
user_responsibilities_two = :user_responsibilities_two,
job_duration_two = :job_duration_two,
job_title_three = :job_title_three,
company_name_three = :company_name_three,
user_responsibilities_three = :user_responsibilities_three,
job_duration_three = :job_duration_three,
job_title_four = :job_title_four,
company_name_four = :company_name_four,
user_responsibilities_four = :user_responsibilities_four,
job_duration_four = :job_duration_four,
job_title_five = :job_title_five,
company_name_five = :company_name_five,
user_responsibilities_five = :user_responsibilities_five,
job_duration_five = :job_duration_five,
edu_orgainzation = :edu_orgainzation,
edu_subject = :edu_subject,
edu_completion = :edu_completion,
edu_orgainzation_two = :edu_orgainzation_two,
edu_subject_two = :edu_subject_two,
edu_completion_two = :edu_completion_two,
edu_orgainzation_three = :edu_orgainzation_three,
edu_subject_three = :edu_subject_three,
edu_completion_three = :edu_completion_three,
edu_orgainzation_four = :edu_orgainzation_four,
edu_subject_four = :edu_subject_four,
edu_completion_four = :edu_completion_four,
edu_orgainzation_five = :edu_orgainzation_five,
edu_subject_five = :edu_subject_five,
edu_completion_five = :edu_completion_five,
language_short = :language_short,
cover_letter = :cover_letter,
last_update = NOW( )
WHERE user_id = $current_user";
$stmt = $conn->prepare($sql);
var_dump($dbh->errorInfo());
$stmt->bindParam(':user_name', $_POST['user_name'], PDO::PARAM_STR);
$stmt->bindParam(':user_email', $_POST['$user_email'], PDO::PARAM_STR);
$stmt->bindParam(':user_phone', $_POST['user_phone'], PDO::PARAM_STR);
$stmt->bindParam(':user_gender', $_POST['user_gender'], PDO::PARAM_STR);
$stmt->bindParam(':employment_status', $_POST['employment_status'], PDO::PARAM_STR);
$stmt->bindParam(':user_min_salary', $_POST['user_min_salary'], PDO::PARAM_STR);
$stmt->bindParam(':user_dob', $_POST['user_dob'], PDO::PARAM_STR);
$stmt->bindParam(':user_location', $_POST['user_location'], PDO::PARAM_STR);
$stmt->bindParam(':user_years_experience', $_POST['user_years_experience'], PDO::PARAM_STR);
$stmt->bindParam(':job_title', $_POST['job_title'], PDO::PARAM_STR);
$stmt->bindParam(':company_name', $_POST['company_name'], PDO::PARAM_STR);
$stmt->bindParam(':user_responsibilities', $_POST['user_responsibilities'], PDO::PARAM_STR);
$stmt->bindParam(':job_duration', $_POST['job_duration'], PDO::PARAM_STR);
$stmt->bindParam(':job_title_two', $_POST['job_title_two'], PDO::PARAM_STR);
$stmt->bindParam(':company_name_two', $_POST['company_name_two'], PDO::PARAM_STR);
$stmt->bindParam(':user_responsibilities_two', $_POST['user_responsibilities_two'], PDO::PARAM_STR);
$stmt->bindParam(':job_duration_two', $_POST['job_duration_two'], PDO::PARAM_STR);
$stmt->bindParam(':job_title_three', $_POST['job_title_three'], PDO::PARAM_STR);
$stmt->bindParam(':company_name_three', $_POST['company_name_three'], PDO::PARAM_STR);
$stmt->bindParam(':user_responsibilities_three', $_POST['user_responsibilities_three'], PDO::PARAM_STR);
$stmt->bindParam(':job_duration_three', $_POST['job_duration_three'], PDO::PARAM_STR);
$stmt->bindParam(':job_title_four', $_POST['job_title_four'], PDO::PARAM_STR);
$stmt->bindParam(':company_name_four', $_POST['company_name_four'], PDO::PARAM_STR);
$stmt->bindParam(':user_responsibilities_four', $_POST['user_responsibilities_four'], PDO::PARAM_STR);
$stmt->bindParam(':job_duration_four', $_POST['job_duration_four'], PDO::PARAM_STR);
$stmt->bindParam(':job_title_five', $_POST['job_title_five'], PDO::PARAM_STR);
$stmt->bindParam(':company_name_five', $_POST['company_name_five'], PDO::PARAM_STR);
$stmt->bindParam(':user_responsibilities_five', $_POST['user_responsibilities_five'], PDO::PARAM_STR);
$stmt->bindParam(':job_duration_five', $_POST['job_duration_five'], PDO::PARAM_STR);
$stmt->bindParam(':edu_orgainzation', $_POST['edu_orgainzation'], PDO::PARAM_STR);
$stmt->bindParam(':edu_subject', $_POST['edu_subject'], PDO::PARAM_STR);
$stmt->bindParam(':edu_completion', $_POST['edu_completion'], PDO::PARAM_STR);
$stmt->bindParam(':edu_orgainzation_two', $_POST['edu_orgainzation_two'], PDO::PARAM_STR);
$stmt->bindParam(':edu_subject_two', $_POST['edu_subject_two'], PDO::PARAM_STR);
$stmt->bindParam(':edu_completion_two', $_POST['edu_completion_two'], PDO::PARAM_STR);
$stmt->bindParam(':edu_orgainzation_three', $_POST['edu_orgainzation_three'], PDO::PARAM_STR);
$stmt->bindParam(':edu_subject_three', $_POST['edu_subject_three'], PDO::PARAM_STR);
$stmt->bindParam(':edu_completion_three', $_POST['edu_completion_three'], PDO::PARAM_STR);
$stmt->bindParam(':edu_orgainzation_four', $_POST['edu_orgainzation_four'], PDO::PARAM_STR);
$stmt->bindParam(':edu_subject_four', $_POST['edu_subject_four'], PDO::PARAM_STR);
$stmt->bindParam(':edu_completion_four', $_POST['edu_completion_four'], PDO::PARAM_STR);
$stmt->bindParam(':edu_orgainzation_five', $_POST['edu_orgainzation_five'], PDO::PARAM_STR);
$stmt->bindParam(':edu_subject_five', $_POST['edu_subject_five'], PDO::PARAM_STR);
$stmt->bindParam(':edu_completion_five', $_POST['edu_completion_five'], PDO::PARAM_STR);
$stmt->bindParam(':language_short', $_POST['language_short'], PDO::PARAM_STR);
$stmt->bindParam(':cover_letter', $_POST['cover_letter'], PDO::PARAM_STR);
$stmt->bindParam(':last_update', $_POST['last_update'], PDO::PARAM_STR);
$stmt->execute();
// echo a message to say the UPDATE succeeded
echo 'success';
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
?>
Thank you very much in advance!
Upvotes: 0
Views: 298
Reputation: 2314
Remove this line:
$stmt->bindParam(':last_update', $_POST['last_update'], PDO::PARAM_STR);
You don't need to bind a parameter here because you're using NOW()
, a MySQL function. Just like the error message says, your number of tokens doesn't match the number of bound parameters.
Upvotes: 1