Can anybody please tell me what is wrong with this code. It gives me the error: Query was empty. It looks perfect to me but I'm obviously missing something small.
<?php require_once('../Connections/dbConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
//STEP 1. COPY THE FILE TO THE IMAGES OFLDER
//test first to see if we are updating the image
if( !empty($_FILES["image"]['name'])){
//create the file path to save the file
$filePath = "downloads/" . $_FILES["image"]['name'];
//check to see if the temp file is uploaded
//$_FILES["INSERT THE NAME OF THE IMAGE FIELD IN YOUR FORM"]['tmp_name']
if(is_uploaded_file($_FILES["image"]['tmp_name'])){
copy($_FILES["image"]['tmp_name'],$filePath);
}
//*********************
}//
//do not update the image
if(empty($filePath)){
$updateSQL = sprintf("UPDATE tbl_clippings SET title=%s, `date`=%s, content=%s, clippings_url=%s, clippingsID=%s WHERE clippingsID=%s",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['content'], "text"),
GetSQLValueString($_POST['clippings_url'], "text"),
//GetSQLValueString($filePath, "text"),
GetSQLValueString($_POST['clippingsID'], "int"));
}else{//update the image
$updateSQL = sprintf("UPDATE tbl_clippings SET title=%s, `date`=%s, content=%s, clippings_url=%s, image=%s, clippingsID=%s WHERE clippingsID=%s",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['content'], "text"),
GetSQLValueString($_POST['clippings_url'], "text"),
GetSQLValueString($filePath, "text"),
GetSQLValueString($_POST['clippingsID'], "int"));
}
mysql_select_db($database_dbConn, $dbConn);
$Result1 = mysql_query($updateSQL, $dbConn) or die(mysql_error());
$updateGoTo = "manage_clippings.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_clippingsRS = "-1";
if (isset($_GET['clippingsID'])) {
$colname_clippingsRS = $_GET['clippingsID'];
}
mysql_select_db($database_dbConn, $dbConn);
$query_clippingsRS = sprintf("SELECT * FROM tbl_clippings WHERE clippingsID = %s", GetSQLValueString($colname_clippingsRS, "int"));
$clippingsRS = mysql_query($query_clippingsRS, $dbConn) or die(mysql_error());
$row_clippingsRS = mysql_fetch_assoc($clippingsRS);
$totalRows_clippingsRS = mysql_num_rows($clippingsRS);
?>