I’m new to programming and I’m currently studying PHP and the database, I got the error ‘Invalid parameter number: parameter was not defined in (on line 28)’ please tell me what the problem is ?
p.s And I also use Google Translator, so don’t be surprised at my poor English.
$post = "Work";
$full_name = "Jack";
$email = "@gmail";
$work_number = "3241";
$number = "8(903)432-19-11";
$parameters = [
["p"=>$post],
["f_n"=>$full_name],
["e"=>$email],
["w_n"=>$work_number],
["n"=>$number]
];
$sql = "INSERT contact_work ($post, $full_name, $email , $work_number , $number) VALUE(:p , :f_n , :e , :w_n , :n)";
$query=$connection->prepare($sql);
$query->execute($parameters);
I tried to look at various guides and answers of those who faced this problem, but I could not find a solution.
2
Answers
There are multiple issue in your code:
The SQL INSERT statement syntax is incorrect. The correct syntax for INSERT statement should be
INSERT INTO table_name (column1, column2, …) VALUES (value1, value2, …).
$parameters array key names should be same as placeholders (:p, :f_n, :e, :w_n, :n).
$parameters = [
‘:p’ => $post,
‘:f_n’ => $full_name,
‘:e’ => $email,
‘:w_n’ => $work_number,
‘:n’ => $number
];
try with below code: