I cant seem to figure out how to correct this error. i’ve tried multiple ways but to no avail.
function.php
function updateData()
{
// Base url to append to extracted links
$baseUrl = 'http://www.sharenet.co.za';
// Starting point to begin extraction
$url = 'http://www.sharenet.co.za/v3/q_sharelookup.php';
// From dbconnect.php
global $pdo;
// Calling function curlGet and storing returned results in $sharenetData variable
$sharenetData = curlGet($url);
// Instantiating new XPath DOM object
$sharenetDataXpath = returnXPathObject($sharenetData);
// Querying for all href links on url
$links = $sharenetDataXpath->query('(//table[@class="dataTable"]//table)[1]//a/@href');
for ($i=0; $i < $links->length; $i++)
{
// Append baseUrl
$url = $baseUrl . $links->item($i)->nodeValue;
// Replace all occurrences of ' ' with '%20'
$url = str_replace(' ', '%20', $url);
// Calling function curlGet and storing returned results in $sharenetData variable
$sharenetData = curlGet($url);
// Instantiating new XPath DOM object
$sharenetDataXpath = returnXPathObject($sharenetData);
// Querying for company short name
$shortnames = $sharenetDataXpath->query('//table[@class="dataTable"]//a/text()');
if ($shortnames->length > 0)
{
$x = 2;
for ($i=0; $i < $shortnames->length; $i++)
{
// extract all shortcodes
$shortcode = $sharenetDataXpath->query('(//table[@class="dataTable"]//tr/td[@class="dataCell"]/text())[' . $x . ']');
// Remove unwanted characters
$name = substr($shortnames->item($i)->nodeValue, 2,-2);
$code = $shortcode->item(0)->nodeValue;
// Increment $x by 3 during loop
$x += 3;
try
{
$sql = "INSERT INTO stock SET shortname = :name WHERE shortcode = :code ";
$s = $pdo->prepare($sql);
$s->bindValue(':name', $name);
$s->bindValue(':code', $code);
$s->execute();
}
catch (PDOException $e)
{
// Show exception error
echo 'Error: ' . $e->getMessage();
exit();
}
}
}
}
}
index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'functions.php';
updateData();
?>
I get the following error:
Error: 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 'WHERE shortcode = 'OAON'' at line 1
Any help?