[SOLVED] Problem with LARGE insert statement

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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

[SOLVED] Problem with LARGE insert statement

Post by dull1554 »

im working on an online catalog for a little furniture busisness and i ran into a error in my sql.

the error:

Code: Select all

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 ')' at line 1
my code:

Code: Select all

<?php
$connection = mysql_connect ("localhost", "", "") or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ("hillside");
if(!isset($_POST&#1111;'submit']))&#123;
Print <<< EOT
<html><head><title>Addpiece</title></head><body><div align="center"><center>
<form method="POST" enctype="multipart/form-data" action="addpiece.php"><center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bordercolor="#111111" width="342">
<tr><td width="343" colspan="2"><p align="center">Add New Piece</td></tr><tr><td width="94"><p align="center">PieceNumber:</td>
<td width="248"><p align="center"><input type="text" name="itemnum"></td></tr><tr><td width="94"><p align="center">Name:</td>
<td width="248"><p align="center"><input type="text" name="title"></td></tr><tr><td width="94"><p align="center">Catagory:</td>
<td width="248"><p align="center"><select name="catagory"><option value="" selected>Please choose catagory</option>
EOT;
$query = mysql_query("SELECT * FROM catagory");
while($array = mysql_fetch_array($query)) &#123;
Print '<option value="'.$array&#1111;'id'].'">'.$array&#1111;'title'].'</option>';
&#125;
PRINT <<< EOT
</select></td></tr><tr><td width="94"><p align="center">Height:</td>
<td width="248"><p align="center"><input type="text" name="height"></td></tr><tr><td width="94"><p align="center">Width:</td>
<td width="248"><p align="center"><input type="text" name="width"></td></tr><tr><td width="94"><p align="center">Depth:</td>
<td width="248"><p align="center"><input type="text" name="depth"></td></tr><tr><td width="94"><p align="center">Image:</td>
<td width="248"><p align="center"><input type="file" name="file"></td></tr><tr><td width="343" colspan="2"><p align="center">
<input type="submit" value="Submit" name="submit">&nbsp;&nbsp;<input type="reset" value="Reset" name="reset"></td>
</tr></table></center></div></form></center></div></body></html>
EOT;
&#125;
if(isset($_POST&#1111;'submit'])) &#123;
function makethumb($sourcefile, $destfile, $imgcomp = 0)
&#123;
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
if(file_exists($g_srcfile))
&#123;
$g_is=getimagesize($g_srcfile);
$g_fw=$g_is&#1111;0]/4;
$g_fh=$g_is&#1111;1]/4;
if(($g_is&#1111;0]-$g_fw)>=($g_is&#1111;1]-$g_fh))
&#123;
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is&#1111;0])*$g_is&#1111;1];
&#125;
else
&#123;
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is&#1111;1])*$g_is&#1111;0];
&#125;
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is&#1111;0], $g_is&#1111;1]);
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
imagedestroy($img_dst);
return true;
&#125;
else
return false;
&#125;
$filename = eregi_replace(" ","_",$_FILES&#1111;"userfile"]&#1111;"name"]);
$query = mysql_query("INSERT INTO furniture (itemnum,title,catagory,height,width,depth,image) VALUES (&#123;$_POST&#1111;'itemnum']&#125;,&#123;$_POST&#1111;'title']&#125;.&#123;$_POST&#1111;'catagory']&#125;,&#123;$_POST&#1111;'height']&#125;,&#123;$_POST&#1111;'width']&#125;,&#123;$_POST&#1111;'depth']&#125;,&#123;$filename&#125;)") or die(mysql_error());
if($query) &#123;
echo "Information Inserted into the Database Correctly!";
&#125;
$filecopy = copy($_FILES&#1111;"file"]&#1111;"tmp_name"], "images/" . $filename);
if($filecopy) &#123;
echo "Image Copied to Images Folder Correctly!";
&#125;
$makethumbnail = makethumb("images/".$_FILES&#1111;"file"]&#1111;"name"],"images/thumbnails/thumb_".$filename,0);
if($filecopy) &#123;
echo "Thumbnail Image Made Correctly!";
&#125;
&#125;
?>
im a little rusty so if anyone could help my out it would be great
~Dull1554
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

First rule of debugging is to take the $query (strip the mysql_query() from that) and echo it out on the screen.
You might see something interesting at that point as;

Code: Select all

... &#123;$_POST&#1111;'title']&#125;.&#123;$_POST&#1111;'catagory']&#125; ...
Should that dot between the two values be there?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

nope, and acctually after i posted....i did just what you suggested and found that error....

plus as i said i was rusty it took a bit for me to figure it out

Code: Select all

$qry = "INSERT INTO furniture (itemnum,title,catagory,height,width,depth,image) VALUES ('".$_POST&#1111;'itemnum']."','".$_POST&#1111;'title']."','".$_POST&#1111;'catagory']."','".$_POST&#1111;'height']."','".$_POST&#1111;'width']."','".$_POST&#1111;'depth']."','".$filename."')";
thats what it should be
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

:D
Yah, I'm no fan of those dots myself.
Post Reply