# Problem with PDO in php page

**URL:** <https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771>\
**Category:** General\
**Created:** [April 3, 2020, 8:48pm UTC](https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771 "2020-04-03T20:48:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![larry29936](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/larry29936/32/140739_2.png) [@larry29936](https://forum.freecodecamp.org/u/larry29936)\
**Post date:** [April 3, 2020, 8:48pm UTC](https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771/1 "2020-04-03T20:48:55Z")

</div>

I’m having a problem with PDO. At the top of my index.php, I have the following:

```auto
<?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:

```auto

   <?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

---

<div class="post-metadata">

**Author:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [April 3, 2020, 8:59pm UTC](https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771/2 "2020-04-03T20:59:36Z")

</div>

Looks like you might have just missed the semicolon in the preceding line.

---

<div class="post-metadata">

**Author:** ![larry29936](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/larry29936/32/140739_2.png) [@larry29936](https://forum.freecodecamp.org/u/larry29936)\
**Post date:** [April 3, 2020, 9:41pm UTC](https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771/3 "2020-04-03T21:41:14Z")

</div>

Thanks for catching that.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 7:00pm UTC](https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/367771/4 "2021-06-01T19:00:21Z")

</div>

Closed on June 1, 2021, 7:00pm UTC


