ukweb Posted November 15, 2007 Share Posted November 15, 2007 Hi folks! Basically I;m constructing the version 2 of the content management suite in work, and up to now its gone well until now, there's one function I;m working on (entitled uploader) which takes a file, uploads it, and resizes it if required, creates a thumbnail if requested, and stores the upload in the images table if required (using a custom insertsql function) but it falls over at the point of entering the info into the database, and I cannot see why. On its own the insertsql functions like a dream but I cannot see whats up when used within my upload function. The code is below and the output of the actual script working on a server at http://click.sjwright.co.uk/click2.php <?php require_once('connections.php'); $msg = 'Start'; // Functions function insertsql($dbselect, $dbuser, $table, $cols, $values, $no_response) { if ((!isset($table)) || (!isset($cols)) || (!isset($values))) { $msg = $msg.'» SQL input parameters incorrect \n'; } else { $insertSQL = sprintf("INSERT INTO ".$table." (".$cols.") VALUES (".$values.") "); mysql_select_db($dbselect, $dbuser); if (mysql_query($insertSQL, $dbuser)) { if (!($no_response == "true")) { $msg = $msg.'» Data entered into table ".$table." successfully \n'; } } else { die('» SQL Encountered some problems: '.mysql_error()); } } } function resizer($source, $output, $r_width, $quality, $no_response) { if ((!isset($source)) || (!isset($output)) || (!isset($rwidth))) { $msg = $msg."» Resizer input parameters incorrect \n"; } else { list($src_width, $src_height) = getimagesize($source); $ratio = ($r_width / $src_width) * 100; $r_height = round(($ratio * $src_height) / 100); $resized = imagecreatetruecolor($r_width, $r_height); $original = imagecreatefromjpeg($source); if(imagecopyresampled($resized, $original, 0, 0, 0, 0, $r_width, $r_thumb, $src_width, $src_height)) { imagejpeg($resized, $source, $quality); if (!($no_response == "True")) { $msg = $msg.'» Image resized successfully \n'; } } } } function uploader($filename, $saveloc, $record, $resize, $no_response, $thumb, $width, $thumbwidth) { if ((!isset($_FILES['userfile']['name'])) || (!isset($saveloc))) { $msg = $msg."» Uploader input parameters incorrect \n"; } else { $imgtypes = array('.jpg','.gif','.bmp','.png'); $filename = date("ymdHis")."_".$_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!is_writable($saveloc)) { $msg = $msg.'» You cannot upload to the specified directory, a permissions error occured'; } else { if(move_uploaded_file($_FILES['userfile']['tmp_name'],$saveloc.$filename)) { if (in_array($ext, $imgtypes)) { if (($resize == "true") && (isset($width))) { resizer($saveloc.$filename, $saveloc.$filename, $width, 100, 'false'); list($a_width, $a_height) = getimagesize($saveloc.$filemame); insertsql($database_click_sql, $click_sql, "images", "site_id, page_id, ident, name, loc, description, width, height", "'$row_login['site_id']', '$_POST['page_id']', '$_POST['ident']', '$_POST['name']', '$saveloc.$filemame', '$_POST['description']', '$a_width', '$a_height'"); if (($thumb == 'true') && ($isset($thumbwidth))) { resizer($saveloc.$filename, $saveloc."thumbs/".$filename, $thumbwidth, 100, 'false'); } } else if ((in_array($ext, $imgtypes)) && (!isset($width))) { if (!($no_response == "True")) { $msg = $msg.'» No width is defined \n'; } } } } else { if (!($no_response == "true")) { $msg = $msg.'» Your upload failed, undefined error \n'; } } } } } echo "If you can see this in the browser the custom functions are fine"; ?> Any help would be received with thanks. Link to comment https://forums.phpfreaks.com/topic/77405-solved-custom-functions-cant-see-whats-wrong/ Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 insertsql($database_click_sql, $click_sql, "images", "site_id, page_id, ident, name, loc, description, width, height", "'$row_login['site_id']', '$_POST['page_id']', '$_POST['ident']', '$_POST['name']', '$saveloc.$filemame', '$_POST['description']', '$a_width', '$a_height'"); should be insertsql($database_click_sql, $click_sql, "images", "site_id, page_id, ident, name, loc, description, width, height", "{$row_login['site_id']}', '{$_POST['page_id']}', '{$_POST['ident']}', '{$_POST['name']}', '$saveloc.$filemame', '{$_POST['description']}', '$a_width', '$a_height'"); also change if (mysql_query($insertSQL, $dbuser)) { if (!($no_response == "true")) { to if (mysql_query($insertSQL, $dbuser) or die(mysql_error())) { if (!($no_response == "true")) { Link to comment https://forums.phpfreaks.com/topic/77405-solved-custom-functions-cant-see-whats-wrong/#findComment-391838 Share on other sites More sharing options...
ukweb Posted November 15, 2007 Author Share Posted November 15, 2007 many thanks! works a treat! Link to comment https://forums.phpfreaks.com/topic/77405-solved-custom-functions-cant-see-whats-wrong/#findComment-391840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.