I am attempting to insert a record to MySQL using PDO, my sql statement can be seen in the following code.
<?php
try{
//include file myfunctions.php allows us to calls functions from it
include ("myfunctions.php");
//Assign function getConnection() from myfunctions.php to variable $db
$db = getConnection();
foreach($_POST['chk'] as $check_value)
{
$check = $check_value;
$fav = "channel/item [title = \"$check\"]";
$holidayDoc = simplexml_load_file('holidays.xml');
$favourites = $holidayDoc->xpath($fav);
foreach($favourites as $currentFav)
{
echo "{$currentFav->link}". "<br \>";
echo "{$currentFav->title}". "<br \>";
echo "{$currentFav->description}". "<br \>";
echo "{$currentFav->pubDate} ". "<br \>";
$sql = "INSERT INTO `saved_holidays` (`subscriberID`, `link`, `pubDate`, `title`, `description`)
VALUES (`John`, `$currentFav->link`, `$currentFav->pubDate`, `$currentFav->title`, `$currentFav->description`)";
$db->exec($sql);
$db = null;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
When this code is executed i am met with the following error message;
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘John’ in
‘field list’
This is no doubt a simple solution to this problem but i cannot seem to see it, can anyone point me in the right direction?
I believe this is because you are using backticks for your values. Change them to single quotes and you should be good
Please refer to this SO question about single quotes versus backticks if you want more information