SQL update syntax problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheMightySpud
Forum Newbie
Posts: 1
Joined: Mon Dec 01, 2008 1:15 pm

SQL update syntax problem

Post by TheMightySpud »

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

Code: Select all

<?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 query 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, specifically to do with the URL=004.jpg part, but I can't figure out how to fix it.

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

Hope someone can point me in the right direction.

Thanks
TheMightySpud
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: SQL update syntax problem

Post by requinix »

If something is supposed to be a string then you need quotes around it.

Code: Select all

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