tefnut
11-29-2007, 08:47 AM
Im updating a record in a MySql database. I can edit and delete ok. Im a but new to PHP so please be patient with me.
I keep getting the following error 'Query was empty'.
Here is the PHP code:
include "Connections/rbs.php";
include "includes/lib.php";
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE listings SET logoFileName=%s, companyName=%s, contactName=%s, fax=%s, companyDetails=%s, tel=%s, fax=%s, email=%s, website=%s, standNumber=%s, postalAddress=%s WHERE id=%s",
GetSQLValueString($_POST['logoFileName']['name'], "text"),
GetSQLValueString($_POST['companyName'], "text"),
GetSQLValueString($_POST['contactName'], "text"),
GetSQLValueString($_POST['companyDetails'], "text"),
GetSQLValueString($_POST['tel'], "text"),
GetSQLValueString($_POST['fax'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['standNumber'], "text"),
GetSQLValueString($_POST['postaladdress'], "text"),
GetSQLValueString($_GET['id'], "int"));
mysql_select_db($database_rbsData, $rbsData );
$Result1 = mysql_query($updateSQL, $rbsData ) or die(mysql_error());
$updateGoTo = "listings.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
// header(sprintf("Location: %s", $updateGoTo));
}
$colname_listings = "-1";
if (isset($_GET['id'])) {
$colname_listings = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_rbsData, $rbsData );
$query_listings = sprintf("SELECT * FROM listings WHERE id = %s", $colname_listings);
$listings = mysql_query($query_listings, $rbsData ) or die(mysql_error());
$row_listings = mysql_fetch_assoc($listings);
$totalRows_listings = mysql_num_rows($listings);
and here is the form and php stuff:
<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" >
Upload your logo:
<input name="logoFileName" id="logoFileName" type="file" class="textBoxes" style="float:right;" / value="<?php echo $row_listings['logoFileName']; ?>">
<hr />
<div>
<div style="float:left; clear:right; ">Company Name</div>
<input name="companyName" type="text" class="textBoxes" id="companyName" style="float:right; " value="<?php echo $row_listings['companyName']; ?>"/>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">Contact Name</div>
<input name="contactName" type="text" class="textBoxes" id="contactName" style="float:right; " value="<?php echo $row_listings['contactName']; ?>"/>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Company Details
</div>
<textarea name="companyDetails" rows="10" class="textBoxes" id="companyDetails" style="float:right;" ><?php echo $row_listings['companyDetails']; ?></textarea>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Tel
</div>
<input name="tel" type="text" class="textBoxes" id="tel" style="float:right;" value="<?php echo $row_listings['tel']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Email
</div>
<input name="email" type="text" class="textBoxes" id="email" style="float:right;" value="<?php echo $row_listings['email']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Website:
</div>
<input name="website" type="text" class="textBoxes" id="website" style="float:right;" value="<?php echo $row_listings['website']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Stand Number
</div>
<input name="standNumber" type="text" class="textBoxes" id="standNumber" style="float:right;" value="<?php echo $row_listings['standNumber']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Postal Address
</div>
<textarea name="postalAddress" rows="6" class="textBoxes" id="postalAddress" style="float:right;"><?php echo $row_listings['postalAddress']; ?></textarea>
</div><input name="Input" type="submit" value="Submit" style="clear:both;float:right;" />
<input type="hidden" name="MM_update" value="form1" >
</form>
please can anyone help?
Thanks
I keep getting the following error 'Query was empty'.
Here is the PHP code:
include "Connections/rbs.php";
include "includes/lib.php";
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE listings SET logoFileName=%s, companyName=%s, contactName=%s, fax=%s, companyDetails=%s, tel=%s, fax=%s, email=%s, website=%s, standNumber=%s, postalAddress=%s WHERE id=%s",
GetSQLValueString($_POST['logoFileName']['name'], "text"),
GetSQLValueString($_POST['companyName'], "text"),
GetSQLValueString($_POST['contactName'], "text"),
GetSQLValueString($_POST['companyDetails'], "text"),
GetSQLValueString($_POST['tel'], "text"),
GetSQLValueString($_POST['fax'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['standNumber'], "text"),
GetSQLValueString($_POST['postaladdress'], "text"),
GetSQLValueString($_GET['id'], "int"));
mysql_select_db($database_rbsData, $rbsData );
$Result1 = mysql_query($updateSQL, $rbsData ) or die(mysql_error());
$updateGoTo = "listings.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
// header(sprintf("Location: %s", $updateGoTo));
}
$colname_listings = "-1";
if (isset($_GET['id'])) {
$colname_listings = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_rbsData, $rbsData );
$query_listings = sprintf("SELECT * FROM listings WHERE id = %s", $colname_listings);
$listings = mysql_query($query_listings, $rbsData ) or die(mysql_error());
$row_listings = mysql_fetch_assoc($listings);
$totalRows_listings = mysql_num_rows($listings);
and here is the form and php stuff:
<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" >
Upload your logo:
<input name="logoFileName" id="logoFileName" type="file" class="textBoxes" style="float:right;" / value="<?php echo $row_listings['logoFileName']; ?>">
<hr />
<div>
<div style="float:left; clear:right; ">Company Name</div>
<input name="companyName" type="text" class="textBoxes" id="companyName" style="float:right; " value="<?php echo $row_listings['companyName']; ?>"/>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">Contact Name</div>
<input name="contactName" type="text" class="textBoxes" id="contactName" style="float:right; " value="<?php echo $row_listings['contactName']; ?>"/>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Company Details
</div>
<textarea name="companyDetails" rows="10" class="textBoxes" id="companyDetails" style="float:right;" ><?php echo $row_listings['companyDetails']; ?></textarea>
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Tel
</div>
<input name="tel" type="text" class="textBoxes" id="tel" style="float:right;" value="<?php echo $row_listings['tel']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
</div>
<input name="email" type="text" class="textBoxes" id="email" style="float:right;" value="<?php echo $row_listings['email']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Website:
</div>
<input name="website" type="text" class="textBoxes" id="website" style="float:right;" value="<?php echo $row_listings['website']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Stand Number
</div>
<input name="standNumber" type="text" class="textBoxes" id="standNumber" style="float:right;" value="<?php echo $row_listings['standNumber']; ?>" />
</div>
<hr />
<div>
<div style="float:left; clear:right; ">
Postal Address
</div>
<textarea name="postalAddress" rows="6" class="textBoxes" id="postalAddress" style="float:right;"><?php echo $row_listings['postalAddress']; ?></textarea>
</div><input name="Input" type="submit" value="Submit" style="clear:both;float:right;" />
<input type="hidden" name="MM_update" value="form1" >
</form>
please can anyone help?
Thanks