ultraloveninja Posted June 10, 2011 Share Posted June 10, 2011 I am working on an upload image script and I can get the update to work, but not the insert. Here's the code. The query is at the bottom: <?php ini_set("display_errors",1); include 'dbconn.php'; $change=""; $abc=""; define ("MAX_SIZE"," 5000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='<div class="msgdiv">You have exceeded the size limit!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=800; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); //$newwidth1=25; //$newheight1=($height/$width)*$newwidth1; //$tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); //imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); $filename = "images/". $_FILES['file']['name']; //$filename1 = "images/small". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); //imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); //imagedestroy($tmp1); }} } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { mysql_query("insert into gallery ('imgpath') values ('$filename')"); //mysql_query("update gallery set imgpath='$filename'"); $change=' <div class="msgdiv">Image Uploaded Successfully!</div>'; } ?> Don't know if I am missing something or what. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/ Share on other sites More sharing options...
fugix Posted June 10, 2011 Share Posted June 10, 2011 how many fields total are in the table that you are trying to insert into Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/#findComment-1227969 Share on other sites More sharing options...
ultraloveninja Posted June 10, 2011 Author Share Posted June 10, 2011 There are two; Id and imgpath but the imgpath is the only one that gets data to insert. The ID one is set to auto increment. I know in the past I've never had to include the ID part in the query unless I have it setup wrong in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/#findComment-1227970 Share on other sites More sharing options...
taquitosensei Posted June 10, 2011 Share Posted June 10, 2011 echo it out to make sure it looks right $sql="insert into gallery ('imgpath') values ('$filename')"; echo $sql; // this will show if there's something obvious causing a problem $result=mysql_query($sql); print_r($result); //this will tell you if there's actually an error with the syntax Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/#findComment-1227971 Share on other sites More sharing options...
Muddy_Funster Posted June 10, 2011 Share Posted June 10, 2011 dont wrap field names inside quotes INSERT INTO gallery (imgpath) VALUES ('$filename') Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/#findComment-1227973 Share on other sites More sharing options...
ultraloveninja Posted June 10, 2011 Author Share Posted June 10, 2011 dont wrap field names inside quotes DAP!!!! That was it... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/238980-insert-into-not-working/#findComment-1227974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.