runnerjp Posted January 25, 2008 Share Posted January 25, 2008 i belive this code should work... wouldnt mind a quick read through to see if it would be able toi upload data into data base.... my main problem tho is im getting a synthax error on line 110 and cant figure out how to solve it...complete mind blank <?php session_start(); //load the config file include("config.php"); require_once '../settings.php'; //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //get users ID $id = $_SESSION['user_id']; //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$id.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$id.$file_ext\">$path_thumbs/$id.$file_ext</a>"; } dbg_out('SUCCESS!'); // %% $Clean = Array(); $Clean['user_id'] = "'" . mysql_real_escape_string($id) . "'"; $Clean['ext'] = "'" . mysql_real_escape_string($file_ext) . "'"; $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}"; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$id.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$id.$file_ext\">$path_big/$id.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; }else{ //if the form hasn't been submitted. //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script>\n\n <br><h3>:: Browse an Image to Upload:</h3>\n <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[php_SELF]\">\n <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\"> <img src='' name='img_vv' width='0'><br>\n Image width will resize to <b>$img_thumb_width</b> with height ratio. <br><input type=\"Submit\" name=\"upForm\" value=\"Upload & Resize\">\n </form> <a href=\"view_gallery.php\">View Images</a>"; } //print copyright echo"<p align=\"right\"><br>Script by: <a href=\"http://www.maaking.com\">maaking.com</a></p> </body> </html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/ Share on other sites More sharing options...
PHP Monkeh Posted January 25, 2008 Share Posted January 25, 2008 }else{ dbg_out('Database insert successful'); } } That's line 100, it looks like that second } shouldn't be there to me. Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448842 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 i tired that allready and it failed to solve the problem... point for tryin to help me tho haha Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448847 Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 Go back through all your IF statements and check the brackets. I noticed a couple that were missing. Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448860 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 looked through got rid of error but now nothing at all apears on the page i just get a blank page <?php session_start(); //load the config file include("config.php"); require_once '../settings.php'; //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //get users ID $id = $_SESSION['user_id']; //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$id.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$id.$file_ext\">$path_thumbs/$id.$file_ext</a>"; } dbg_out('SUCCESS!'); // %% $Clean = Array(); $Clean['user_id'] = "'" . mysql_real_escape_string($id) . "'"; $Clean['ext'] = "'" . mysql_real_escape_string($file_ext) . "'"; $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}"; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$id.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$id.$file_ext\">$path_big/$id.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; } else{ dbg_out('Database insert successful'); } //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script>\n\n <br><h3>:: Browse an Image to Upload:</h3>\n <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[php_SELF]\">\n <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\"> <img src='' name='img_vv' width='0'><br>\n Image width will resize to <b>$img_thumb_width</b> with height ratio. <br><input type=\"Submit\" name=\"upForm\" value=\"Upload & Resize\">\n </form> <a href=\"view_gallery.php\">View Images</a>"; //print copyright echo"<p align=\"right\"><br>Script by: <a href=\"http://www.maaking.com\">maaking.com</a></p> </body> </html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448922 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 ok been messing around wiht it and i have got the image to upload to file ect but it does not appear to add the data into the db and i have no idea why as from what i see there should be no reason not to ?? <?php session_start(); //load the config file include("config.php"); require_once '../settings.php'; //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //get users ID $id = $_SESSION['user_id']; //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$id.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$id.$file_ext\">$path_thumbs/$id.$file_ext</a>"; } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$id.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$id.$file_ext\">$path_big/$id.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; }else{ //if the form hasn't been submitted. //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script>\n\n <br><h3>:: Browse an Image to Upload:</h3>\n <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[php_SELF]\">\n <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\"> <img src='' name='img_vv' width='0'><br>\n Image width will resize to <b>$img_thumb_width</b> with height ratio. <br><input type=\"Submit\" name=\"upForm\" value=\"Upload & Resize\">\n </form> <a href=\"view_gallery.php\">View Images</a>"; dbg_out('SUCCESS!'); // %% $Clean = Array(); $Clean['user_id'] = "'" . mysql_real_escape_string($id) . "'"; $Clean['ext'] = "'" . mysql_real_escape_string($file_ext) . "'"; $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}"; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448950 Share on other sites More sharing options...
adam291086 Posted January 25, 2008 Share Posted January 25, 2008 when ever you execute an sql command you should put or die (mysql_error()); at the end of is. Therefore if there is an error with you syntax it will tell you. Otherwise you get a blank screen. Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448986 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 i added it in dbg_out('SUCCESS!'); // %% $Clean = Array(); $Clean['user_id'] = "'" . mysql_real_escape_string($id) . "'"; $Clean['ext'] = "'" . mysql_real_escape_string($file_ext) . "'"; $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}" or die (mysql_error()); $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } } ?> but in neither getting data inserted into the db nor an error stating other wise its as if the code had blanked out the area to which it must add data to db... any reason for this? Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-448994 Share on other sites More sharing options...
PHP Monkeh Posted January 25, 2008 Share Posted January 25, 2008 Considering your if() statements are all over the place it's really hard to tell what's going on in there. Read up on some articles about coding structure and indentation etc it can really help. As for your problem, the reason nothing will be getting output is probably because nothing's being called, as in, because of your if() statements none of them will be ringing true so they'll never output the code they have within their { } Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-449046 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 so will i need to re_write the whole of the code Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-449124 Share on other sites More sharing options...
PHP Monkeh Posted January 25, 2008 Share Posted January 25, 2008 You don't necessarily have to rewrite everything, just go through and space it out a little, doing indentation where it's needed and putting } on new lines etc. That way you can see exactly where your if() statements begin and end, and will let you fix errors much easier. Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-449131 Share on other sites More sharing options...
runnerjp Posted January 25, 2008 Author Share Posted January 25, 2008 ok but i still done see why the data is not been included into the database Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-449151 Share on other sites More sharing options...
runnerjp Posted January 31, 2008 Author Share Posted January 31, 2008 ok guys re-continuing with this lol <?php session_start(); //load the config file include("config.php"); require_once '../settings.php'; //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //get users ID $id = $_SESSION['user_id']; //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$id.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$id.$file_ext\">$path_thumbs/$id.$file_ext</a>"; } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$id.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$id.$file_ext\">$path_big/$id.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; }else{ //if the form hasn't been submitted. //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script>\n\n <br><h3>:: Browse an Image to Upload:</h3>\n <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[php_SELF]\">\n <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\"> <img src='' name='img_vv' width='0'><br>\n Image width will resize to <b>$img_thumb_width</b> with height ratio. <br><input type=\"Submit\" name=\"upForm\" value=\"Upload & Resize\">\n </form> <a href=\"view_gallery.php\">View Images</a>"; dbg_out('SUCCESS!'); // %% $Clean = Array(); $Clean['user_id'] = "'" . mysql_real_escape_string($id) . "'"; $Clean['ext'] = "'" . mysql_real_escape_string($file_ext) . "'"; $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}" or die (mysql_error()); $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } } ?> it all works apart from the part it adds the information into the database... i need to do this to fin dthe exe of the file so i can load it up... any help to fix this >?? Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454420 Share on other sites More sharing options...
haku Posted January 31, 2008 Share Posted January 31, 2008 At a quick glance (as in I only looked at your $query and not the rest of your code), I'd say that you have to take the single quotes out of this line of code: (`user_id`, `ext`, `created`, `modified`) Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454439 Share on other sites More sharing options...
runnerjp Posted January 31, 2008 Author Share Posted January 31, 2008 nope i get MySQL returned an empty result set annoyin as the picture gets resized fine and placed into a folder lol just misisng part where i can call on the diff pictured lol Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454443 Share on other sites More sharing options...
haku Posted January 31, 2008 Share Posted January 31, 2008 Add single quotes around each of these: {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454448 Share on other sites More sharing options...
tibberous Posted January 31, 2008 Share Posted January 31, 2008 Did you write the whole thing, then run it? You need to write shit like two lines at a time. Or, if you can't because of loops or whatever, then at least go back and test the variables values with die/print_r intermittently. Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454450 Share on other sites More sharing options...
runnerjp Posted January 31, 2008 Author Share Posted January 31, 2008 well tbh i did that with the whole image thing.. with help form gusy on here... but just adding to db does not work... tired just $sql = " INSERT INTO `user_images` `user_id`, `ext`, `created`, `modified` VALUES ( {$Clean['user_id']}, {$Clean['file_ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } } and does not work... i dont even gt my ('ERROR: ' . mysql_error()); haku tried it and i get errors Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454464 Share on other sites More sharing options...
runnerjp Posted January 31, 2008 Author Share Posted January 31, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/87752-unexpected/#findComment-454558 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.