Jump to content

my sql syntax error for values()


bryanptcs

Recommended Posts

I am using php to store client info as well as files uploaded by the client.  When running the php I get the following mysql error:

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 'values(null,'image/pjpeg','ÿØÿà\0JFIF\0\0È\0È\0\0ÿá!HExif\0\0MM\0*\0\0\0\0' at line 1

here is my code
[code]

<?php

$host = "";
$user = "";
$pass = "";
$db = "";

$cn = mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");

$pureFile = addslashes(fread(fopen($file,"r"), filesize($file)));
$business = stripslashes($_POST['business']);
$address = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$contact = stripslashes($_POST['contact']);
$email = stripslashes($_POST['email']);
$salesrep = stripslashes($_POST['salesrep']);
$phone = stripslashes($_POST['phone']);

$sql  = "insert into upload SET id='$id' , values(null,'$file_type','$pureFile'),  business='$business', address='$address', city='$city', contact='$contact', salesrep='$salesrep', phone='$phone', email='$email'";
$rc = mysql_query($sql,$cn)or die(mysql_error());

$sql = "select * from upload";
$rc = mysql_query($sql,$cn);


$rw = mysql_fetch_object($rc);

header("Content-type: $rw->type");
print($rw->filename);




?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/30563-my-sql-syntax-error-for-values/
Share on other sites

I'm no expert but your sql looks like it could be wrong.

$sql  = "insert into upload SET id='$id' , values(null,'$file_type','$pureFile'),  business='$business', address='$address', city='$city', contact='$contact', salesrep='$salesrep', phone='$phone', email='$email'";

I would suspect it should look like this...

sql = "INSERT INTO upload (id, business, address, city, contact, salesrep, phone, email) VALUES ('$id', '$business', $address', '$city', '$contact', '$salesrep', '$phone', '$email)";

Your SQL looks more like an UPDATE SQL Modified......

-John

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.