Click to See Complete Forum and Search --> : Updating a database proble - 'Query was empty'


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

sstalder
11-29-2007, 09:23 AM
Try to set your updateSQL to this:

$updateSQL = "UPDATE listings SET logoFileName=".GetSQLValueString($_POST['logoFileName']['name'], "text").",
companyName=".GetSQLValueString($_POST['companyName'], "text").",
contactName=".GetSQLValueString($_POST['contactName'], "text").",
companyDetails=".GetSQLValueString($_POST['companyDetails'], "text").",
tel=".GetSQLValueString($_POST['tel'], "text").",
fax=".GetSQLValueString($_POST['fax'], "text").",
email=".GetSQLValueString($_POST['email'], "text").",
website=".GetSQLValueString($_POST['website'], "text").",
standNumber=".GetSQLValueString($_POST['standNumber'], "text").",
postalAddress=".GetSQLValueString($_POST['postaladdress'], "text")."'
WHERE id = " . GetSQLValueString($_GET['id'], "int");

tefnut
12-12-2007, 06:15 AM
Hi Many thanks, but now I get this error:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' WHERE id = 35' at line 10'

cheers for your help

sstalder
12-12-2007, 08:45 AM
Can you please do this to echo your query out and past it here?


//$Result1 = mysql_query($updateSQL, $rbsData ) or die(mysql_error());
echo $updateSQL;

tefnut
12-13-2007, 05:22 AM
OK, Now i get this:
UPDATE listings SET logoFileName=NULL, companyName='test555', contactName='test', companyDetails=NULL, tel=NULL, fax=NULL, email=NULL, website=NULL, standNumber=NULL, postalAddress=NULL' WHERE id = 35

thanks

sstalder
12-13-2007, 07:41 AM
Ah I see the error now, I forgot to remove a single quote:

$updateSQL = "UPDATE listings SET logoFileName=".GetSQLValueString($_POST['logoFileName']['name'], "text").",
companyName=".GetSQLValueString($_POST['companyName'], "text").",
contactName=".GetSQLValueString($_POST['contactName'], "text").",
companyDetails=".GetSQLValueString($_POST['companyDetails'], "text").",
tel=".GetSQLValueString($_POST['tel'], "text").",
fax=".GetSQLValueString($_POST['fax'], "text").",
email=".GetSQLValueString($_POST['email'], "text").",
website=".GetSQLValueString($_POST['website'], "text").",
standNumber=".GetSQLValueString($_POST['standNumber'], "text").",
postalAddress=".GetSQLValueString($_POST['postaladdress'], "text")."
WHERE id = " . GetSQLValueString($_GET['id'], "int");

tefnut
12-13-2007, 08:06 AM
YOU STAR!
Thanks that worked.
xxxxxx