I’m having a problem with PDO. At the top of my index.php, I have the following:
<?php
session_start();
// start of script every time.
// setup a path for all of your canned php scripts
$php_scripts = '/home/foxclone/php/'; // a folder above the web accessible tree
// load the pdo connection module
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';
//*******************************
// Begin the script here
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data")):
{
echo "Failed to connect to database" ;
exit;
}
else:
{
$sql = "INSERT INTO Downloads (ip_address,filename) VALUES ('$ip','$down')";
// use exec() because no results are returned
$pdo->exec($sql);
}
endif;
//exit();
?>
Further into index.php I have a download section that I want to record in the same table:
<?php
$files = glob('download/*.iso');
$file = $files[count($files) -1];
$filename = basename($file);
$md5file = md5_file($file);
?>
<div class="container">
<div class="divL">
<h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3>
<center> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center>
<?php
$down=$filename
$sql = "INSERT INTO Downloads (ip_address,filename) VALUES ('$ip','$down')"; <-- parse error here
$pdo->exec($sql);
?>
I’m getting the following error: Parse error: syntax error, unexpected ‘$sql’ (T_VARIABLE) in /home/foxclone/test.foxclone.com/index.php but don’t understand why. Do I not need the $sql line?
Thanks in advance,
Larry