Skip to main content
Participant
August 6, 2006
Question

MySQL error while Updating Record

  • August 6, 2006
  • 1 reply
  • 228 views
Hi

I'm newbie so your help will be welcomed.
While I'm trying to Update Record, the following error occurs:

" 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 '' at line 1".

This is the code that gives me headache:

"<?php require_once('../../../../Inetpub/wwwroot/theHotel/Connections/connHTL.php'); ?>
<?php
$colname_rsBooking = "-1";
if (isset($_GET['ID'])) {
$colname_rsBooking = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_connHTL, $connHTL);
$query_rsBooking = sprintf("SELECT * FROM bookings WHERE ID = %s", $colname_rsBooking);
$rsBooking = mysql_query($query_rsBooking, $connHTL) or die('HERE IS THE ERROR, I GUESS' . mysql_error());
$row_rsBooking = mysql_fetch_assoc($rsBooking);
$totalRows_rsBooking = mysql_num_rows($rsBooking);

$colname_rsClient = "-1";
if (isset($_GET['clientID'])) {
$colname_rsClient = (get_magic_quotes_gpc()) ? $_GET['clientID'] : addslashes($_GET['clientID']);
}
mysql_select_db($database_connHTL, $connHTL);
$query_rsClient = sprintf("SELECT * FROM clients WHERE ID = %s", $colname_rsClient);
$rsClient = mysql_query($query_rsClient, $connHTL) or die('NE MOZAM' . mysql_error());
$row_rsClient = mysql_fetch_assoc($rsClient);
$totalRows_rsClient = mysql_num_rows($rsClient);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> etc......"


I want to know if this is a syntax , MySQL or PHP error. I've tried things, but no results.
PLS HELP!
Thanks in advance!

This topic has been closed for replies.

1 reply

Inspiring
August 6, 2006
dedurus wrote:
> " 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 '' at line 1".

The error message is clear in one respect - it's an error of MySQL
syntax. What it doesn't tell you is what the error is. The way to find
out is to use echo to display the SQL query onscreen. I suspect that
what's happening is that either ID or clientID haven't been defined.


> $query_rsBooking = sprintf("SELECT * FROM bookings WHERE ID = %s",
> $colname_rsBooking);

Display the value of the SQL query here

echo $query_rsBooking.'<br />';

> $rsBooking = mysql_query($query_rsBooking, $connHTL) or die('HERE IS THE
> ERROR, I GUESS' . mysql_error());
> $row_rsBooking = mysql_fetch_assoc($rsBooking);
> $totalRows_rsBooking = mysql_num_rows($rsBooking);
>
> $colname_rsClient = "-1";
> if (isset($_GET['clientID'])) {
> $colname_rsClient = (get_magic_quotes_gpc()) ? $_GET['clientID'] :
> addslashes($_GET['clientID']);
> }
> mysql_select_db($database_connHTL, $connHTL);
> $query_rsClient = sprintf("SELECT * FROM clients WHERE ID = %s",
> $colname_rsClient);

And again, here:

echo $query_rsClient;

> $rsClient = mysql_query($query_rsClient, $connHTL) or die('NE MOZAM' .
> mysql_error());

Once you know what the SQL queries look like, you can begin troubleshooting.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/