I am migrating from normal SQL to PDO because I let a friend of mine test if I have any weak points and he adviced me to PDO because he found a lot of weak points.
So here is my full error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' in /home/ubuntu/workspace/post.php on line 54
( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? (
id
,title
,info_bys
,info_shorts
,info_longs
,
And here is my code:
$stmt = $db->prepare("INSERT INTO :portal
(`id`, `title`, `info_bys`, `info_shorts`, `info_longs`, `email`, `filename`, `filepath`, `filename2`, `filepath2`, `approved`)
VALUES ('', ':title', ':by_information', ':short', ':long_information', ':email', ':filename', ':filetarget', ':filename2', ':filetarget2', 'false'");
$stmt->execute(array(':portal' => $portal, ':title' => $title, ':by_information' => $by_information, ':short' => $short, ':long_information' => $long_information, ':email' => $email, ':filename' => $fileName, ':filetarget' => $fileTarget, ':filename2' => $fileName2, ':filetarget2' => $fileTarget ));
echo $affected_rows.' were affected';
Is there something I cant use in PDO that I can use in SQL or am I just typing the wrong stuff.
Hope someone can help.
EDIT:
New code:
function buildQuery( $get_var )
{
switch($get_var)
{
case 1:
$portal = $_POST['portal'];
break;
}
$stmt = $db->prepare("INSERT INTO :portal
(`id`, `title`, `info_bys`, `info_shorts`, `info_longs`, `email`, `filename`, `filepath`, `filename2`, `filepath2`, `approved`)
VALUES (:title, :by_information, :short, :long_information, :email, :filename, :filetarget, :filename2, :filetarget2, 'false'");
$stmt->execute(array(':portal' => $portal, ':title' => $title, ':by_information' => $by_information, ':short' => $short, ':long_information' => $long_information, ':email' => $email, ':filename' => $fileName, ':filetarget' => $fileTarget, ':filename2' => $fileName2, ':filetarget2' => $fileTarget ));
echo $affected_rows.' were affected';
}