Hi all,

Could anyone help me with this one?

the form is in a seperate file, which the info gets passed to this php file.

The problem is, I'm getting a syntax error on the query and I can't figure out what I'm doing wrong.

<?php
$sUserName  = $_POST['username'];
$sUserEmail = $_POST['useremail'];
$sUserDesc  = $_POST['userdesc'];
$sUserFile  = $_POST['userfile'];
$nID  = $_POST['ID'];

//=====================================//
// Database Section
//=====================================//
// creates a new Common-Object-Model (COM) connection object
	$adoCon = new COM("ADODB.Connection");

// the path to the folder holding this PHP script
	$sHere = dirname(__FILE__);

// opens the connection using a standard Access2007 connection string
	$adoCon-> Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=$sHere/dbase/test1.accdb");

$adoCon->Execute
(	"UPDATE tbltest
	SET id='$nID', Descripton='$sUserDesc', URL='$sUserFile', UploadedBy='$sUserName', Email='$sUserEmail'
	WHERE
	id='$nID';"
);

if (@is_uploaded_file($_FILES['$sUserFile']["tmp_name"])) {
copy($_FILES['$sUserFile']["tmp_name"], "upload/grid/" . $_FILES['$sUserFile']["name"]);
echo "<p>File uploaded successfully.</p>";
}

?>

Thanks
TheMightySpud

    Debug 101
    echo the query string to see what you are passing in to the db.

    Forum 101
    If you have an error message then don't talk about it: post it.

      16 days later

      Okay, been plugging away at this for a while........

      <?php 
      
      $sUserName  = $_POST['username'];
      $sUserEmail = $_POST['useremail'];
      $sUserDesc  = $_POST['userdesc'];
      $nID  = $_POST['ID'];
      
      $imageinfo = getimagesize($_FILES['userfile']['tmp_name']); 
      
      $blacklist = array(".php", ".phtml", ".htm", ".zip", ".exe", ".asp", ".aspx", ".xml"); 
      
      foreach ($blacklist as $item) { 
      if(preg_match("/$item\$/i", $_FILES['userfile']['name'])) { 
      echo "We do not allow uploading PHP files or executable scripts\n"; 
      exit; 
      } 
      } 
      
      $uploaddir = 'images/grid/'; 
      $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); 
      
      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
      echo "File is valid, and was successfully uploaded.\n"; 
      $sUserFile = ($_FILES['userfile']['name']);
      echo "<br>";
      echo $nID;
      echo "<br><Br><Br>";
      echo $sUserFile;
      echo "<br><br>";
      
      //=====================================//
      // Database Section
      //=====================================//
      // creates a new Common-Object-Model (COM) connection object
      	$adoCon = new COM("ADODB.Connection");
      
      // the path to the folder holding this PHP script
      	$sHere = dirname(__FILE__);
      
      // opens the connection using a standard Access2007 connection string
      	$adoCon-> Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=$sHere/dbase/test1.accdb");
      
       $sSQL =	"UPDATE tbltest SET Descripton=$sUserDesc, URL=$sUserFile, UploadedBy=$sUserName, Email=$sUserEmail WHERE id=$nID;";
      
      echo $sSQL;
      echo "<br>";
      
      $adoCon->Execute($sSQL);
      
      } else { 
      echo "File uploading failed.\n"; 
      } 
      
      ?>
      

      Everything is working fine, except for the query.

      I've echoed the quesry string and it gives the following....

      UPDATE tbltest SET Descripton=wdad, URL=004.jpg, UploadedBy=ee, Email=ssdaa WHERE id=4;

      Which is exactly what needs to go across to the database.

      But something is stopping it from being transferred.....and I get this error.

      Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Access Database Engine<br/><b>Description:</b> Syntax error (missing operator) in query expression '004.jpg'.' in C:\Program Files\EasyPHP 2.0b1\www\magpie3\upload.php:48 Stack trace: #0 C:\Program Files\EasyPHP 2.0b1\www\magpie3\upload.php(48): com->Execute('UPDATE tbltest ...') #1 {main} thrown in C:\Program Files\EasyPHP 2.0b1\www\magpie3\upload.php on line 48

      I'm pretty sure it's something to do with the query, but can't figure out where I'm going wrong.

      I know I can connect to the database and modify it as I've tried a 'delete row' query with success.

      Thanks
      TheMightySpud

        You're missing quotes around the string values. Description='wdad' and so on.

          The first one Description=wdad I at first thought, oh, he's updating with a joined table and that's a field name. By the third one though, yeah. Lack of quotes. 🙂

            Write a Reply...