Link to home
Start Free TrialLog in
Avatar of kirkheaton25
kirkheaton25

asked on

PHP PDO Insert Error

I am trying to insert data into a mysql database using PDO. The code is:
$query = "INSERT INTO `Staff` (`email`, `fullname`, `mobile`, `telephone`, `work-phone`, `faddress`, `postcode`, `marital`, `children`, `dob`, `hobbies`, `health`, `gid`, `cv`, `wages`, `employment`) 
	VALUES 
	(:email, :fullname, :mobile, :telephone, :work-phone, :faddress, :postcode, :marital, :children, :dob, :hobbies, :health, :gid, :cv, :wages, :employment)";
	
	$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
	$q = $dbh->prepare($query);
	
	$insert = array(':email'=>$contact,
		':fullname' => $fullname,
		':mobile' => $mofo,
		':telephone' => $telephone,
		':work-phone' => $workTelephone,
		':faddress' => $faddress,
		':postcode' => $pc,
		':marital' => $ms,
		':children' => $children,
		':dob' => $dob,
		':hobbies' => $hobbies,
		':health' => $health,
		':gid' => $gid,
		':cv' => $cv,
		':wages' => $wages,
		':employment' => $empl);
	
	$q->execute($insert);

Open in new window


however, I am getting the following error:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined on line 67
SQLSTATE[HY093]: Invalid parameter number on line 67
I'm new to PDO so could someone please tell me what the problem is here.
Thanks.
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

greetings kirkheaton25, , the way to format your insert SQL, seems incorrect to me, as you place unneeded single quotes around your table name and columns.
I have used this syntax, and it works for me -

$stmt = $dbo->prepare('INSERT INTO authors (author,csvId) VALUES (:aut,:csvId)');
$params = array(':aut'=>$auth,':csvId'=>$cid);
$stmt->execute($params);
ASKER CERTIFIED SOLUTION
Avatar of kirkheaton25
kirkheaton25

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kirkheaton25
kirkheaton25

ASKER

No other answers provided resolution or pointed me towards the resolution.