Jump to content

Where's the problem?


Recommended Posts

Hi everyone

I'm doing some php application using dreamweaver, PHP5 and MySql, and I have a problem, which I guess someone could fix it. Whenever I press the Submit button, I get the following error msg:
[color=red]"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"[/color].

The code of the page is:

<?php require_once('Connections/connHTL.php'); ?>
<?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"] == "bookroom")) {
  $updateSQL = sprintf("UPDATE bookings SET clientID=%s, startDate=%s, endDate=%s, adults=%s, children=%s, roomType=%s, roomOptions=%s, networkConnection=%s, PC=%s, requirements=%s WHERE ID=%s",
                      GetSQLValueString($_POST['clientID'], "int"),
                      GetSQLValueString($_POST['startDate'], "date"),
                      GetSQLValueString($_POST['endDate'], "date"),
                      GetSQLValueString($_POST['adults'], "int"),
                      GetSQLValueString($_POST['children'], "int"),
                      GetSQLValueString($_POST['roomType'], "text"),
                      GetSQLValueString($_POST['roomOptions'], "int"),
                      GetSQLValueString(isset($_POST['networkConnection']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString(isset($_POST['PC']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['requirements'], "text"),
                      GetSQLValueString($_POST['bookingID'], "int"));

  mysql_select_db($database_connHTL, $connHTL);
  $Result1 = mysql_query($updateSQL, $connHTL) or die(mysql_error());

  $updateGoTo = "booking_updated.php?ID=".$_POST_VARS['bookingID']."&clientID=".$_POST_VARS['clientID']."";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsBookings = "-1";
if (isset($_POST['bookingID'])) {
  $colname_rsBookings = (get_magic_quotes_gpc()) ? $_POST['bookingID'] : addslashes($_POST['bookingID']);
}
mysql_select_db($database_connHTL, $connHTL);
$query_rsBookings = sprintf("SELECT * FROM bookings WHERE ID = %s", $colname_rsBookings);
$rsBookings = mysql_query($query_rsBookings, $connHTL) or die(mysql_error());
$row_rsBookings = mysql_fetch_assoc($rsBookings);
$totalRows_rsBookings = mysql_num_rows($rsBookings);

$varBookingID_rsClient = "0";
if (isset($row_rsBooking['clientID'])) {
  $varBookingID_rsClient = (get_magic_quotes_gpc()) ? $row_rsBooking['clientID'] : addslashes($row_rsBooking['clientID']);
}
mysql_select_db($database_connHTL, $connHTL);
$query_rsClient = sprintf("SELECT * FROM clients WHERE clients.ID = %s", $varBookingID_rsClient);
$rsClient = mysql_query($query_rsClient, $connHTL) or die(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">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<!-- TemplateBeginEditable name="doctitle" -->
<title>Home Page</title>
<!-- TemplateEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="inc_pics/mm_travel2.css" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
//--------------- LOCALIZEABLE GLOBALS ---------------
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
//---------------  END LOCALIZEABLE  ---------------

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<style type="text/css">
<!--
.style1 {
color: #CC0000;
font-weight: bold;
}
.style3 {font-size: 14px}
-->
</style>
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>
<body bgcolor="#C0DFFD">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr bgcolor="#3366CC">
    <td colspan="3" rowspan="2"><img src="inc_pics/mm_travel_photo.jpg" alt="Header image" width="382" height="127" border="0" /></td>
    <td height="63" colspan="3" id="logo" valign="bottom" align="center" nowrap="nowrap">Hotel Struga </td>
    <td width="4">&nbsp;</td>
  </tr>

  <tr bgcolor="#3366CC">
    <td height="64" colspan="3" id="tagline" valign="top" align="center">Струга, Македонија </td>
<td width="4">&nbsp;</td>
  </tr>

  <tr>
    <td colspan="7" bgcolor="#003366"><img src="inc_pics/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
  </tr>

  <tr bgcolor="#CCFF99">
  <td height="25" colspan="7" id="dateformat">&nbsp;&nbsp;
    <script language="JavaScript" type="text/javascript">
      document.write(TODAY); </script></td>
  </tr>
<tr>
    <td colspan="7" bgcolor="#003366"><img src="inc_pics/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
  </tr>

<tr>
    <td width="132" valign="top" bgcolor="#E6F3FF">
<table border="0" cellspacing="0" cellpadding="0" width="132" id="navigation">
        <tr>
          <td width="74" align="right" valign="bottom">&nbsp;<br />
&nbsp;<strong>MK</strong><br /></td>
          <td width="79" align="center" valign="bottom"><span class="style1">ENGLISH</span></td>
          <td width="79" align="center" valign="bottom">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">Главна</a></td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">Резервации</a></td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">Промени резервација </a></td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">Откажи резервација </a></td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">За нас </a></td>
        </tr>
        <tr>
          <td colspan="3"><a href="javascript:;" class="navText">Контакт</a></td>
        </tr>
      </table>
<br />
  &nbsp;<br />
  &nbsp;<br />
  &nbsp;<br /> </td>
    <td colspan="5" align="center" valign="top"><img src="inc_pics/mm_spacer.gif" alt="" width="50" height="1" border="0" /><img src="inc_pics/mm_spacer.gif" alt="" width="50" height="1" border="0" /><br />
    &nbsp;<!-- TemplateBeginEditable name="region" -->
    <table width="600" border="0">
      <tr>
        <th class="pageName style3" scope="col">Thank you, <?php echo $row_rsClient['title']; ?> <?php echo $row_rsClient['firstName']; ?> <?php echo $row_rsClient['lastName']; ?>, you can change your booking details below </th>
      </tr>
    </table>
    <!-- TemplateEndEditable --><br />
    <form id="bookroom" name="bookroom" method="POST" action="<?php echo $editFormAction; ?>">
      <table width="600" border="0">
        <tr>
          <td width="251" align="right" class="bodyText">Arrival Date </td>
          <td width="339" class="bodyText"><label>
            <input name="startDate" type="text" class="bodyText" id="startDate" value="<?php echo $row_rsBookings['startDate']; ?>" maxlength="10" />
            (yyyy-mm-dd)</label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Departure Date </td>
          <td class="bodyText"><label>
            <input name="endDate" type="text" class="bodyText" id="endDate" value="<?php echo $row_rsBookings['endDate']; ?>" maxlength="10" />
            (yyyy-mm-dd)</label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Room Type </td>
          <td class="bodyText"><label>
            <select name="roomType" class="bodyText" id="roomType">
              <option value="Single" selected="selected" <?php if (!(strcmp("Single", $row_rsBookings['roomType']))) {echo "selected=\"selected\"";} ?>>Single</option>
              <option value="Twin Bed" <?php if (!(strcmp("Twin Bed", $row_rsBookings['roomType']))) {echo "selected=\"selected\"";} ?>>Twin Bed</option>
              <option value="Double" <?php if (!(strcmp("Double", $row_rsBookings['roomType']))) {echo "selected=\"selected\"";} ?>>Double</option>
              <option value="Suite" <?php if (!(strcmp("Suite", $row_rsBookings['roomType']))) {echo "selected=\"selected\"";} ?>>Suite</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">In Room Extras Required </td>
          <td class="bodyText"><label>
            <input <?php if (!(strcmp($row_rsBookings['networkConnection'],1))) {echo "checked=\"checked\"";} ?> name="networkConnection" type="checkbox" id="networkConnection" value="1" />
            Network Connection </label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">&nbsp;</td>
          <td class="bodyText"><label>
            <input <?php if (!(strcmp($row_rsBookings['PC'],1))) {echo "checked=\"checked\"";} ?> name="PC" type="checkbox" id="PC" value="1" />
            PC</label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Number of Adults </td>
          <td class="bodyText"><label>
            <select name="adults" id="adults">
              <option value="1" <?php if (!(strcmp(1, $row_rsBookings['adults']))) {echo "selected=\"selected\"";} ?>>1</option>
<option value="2" <?php if (!(strcmp(2, $row_rsBookings['adults']))) {echo "selected=\"selected\"";} ?>>2</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Number of Children </td>
          <td class="bodyText"><label>
            <select name="children" id="children">
              <option value="0" <?php if (!(strcmp(0, $row_rsBookings['children']))) {echo "selected=\"selected\"";} ?>>0</option>
              <option value="1" <?php if (!(strcmp(1, $row_rsBookings['children']))) {echo "selected=\"selected\"";} ?>>1</option>
              <option value="2" <?php if (!(strcmp(2, $row_rsBookings['children']))) {echo "selected=\"selected\"";} ?>>2</option>
<option value="3" <?php if (!(strcmp(3, $row_rsBookings['children']))) {echo "selected=\"selected\"";} ?>>3</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Room Options</td>
          <td class="bodyText"><p>
              <label>
              <input <?php if (!(strcmp($row_rsBookings['roomOptions'],"0"))) {echo "checked=\"checked\"";} ?> type="radio" name="roomOptions" value="0" />
                Smoking</label>
              <br />
              <label>
              <input <?php if (!(strcmp($row_rsBookings['roomOptions'],"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="roomOptions" value="1" />
                Non Smoking</label>
              <br />
            </p>
            <label></label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">Special Reqiurements </td>
          <td class="bodyText"><label>
            <textarea name="requirements" cols="30" rows="6" class="bodyText" id="requirements" onblur="MM_validateForm('startDate','','R','endDate','','R');return document.MM_returnValue"><?php echo $row_rsBookings['requirements']; ?></textarea>
          </label></td>
        </tr>
        <tr>
          <td align="right" class="bodyText">&nbsp;</td>
          <td class="bodyText">&nbsp;</td>
        </tr>
        <tr>
          <td align="right" class="bodyText">&nbsp;</td>
          <td class="bodyText"><label>
            <input name="Submit" type="submit" class="bodyText" value="Change my Booking" />
          </label></td>
        </tr>
        <tr>
          <td colspan="2" align="right" class="bodyText"><input name="bookingID" type="hidden" id="bookingID" value="<?php echo $row_rsBookings['ID']; ?>" />
          <input name="clientID" type="hidden" id="clientID" value="<?php echo $row_rsBookings['clientID']; ?>" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_update" value="bookroom">
    </form>
    </td>
    <td width="4">&nbsp;</td>
  </tr>
  <tr>
    <td width="132">&nbsp;</td>
    <td width="83">&nbsp;</td>
    <td width="167">&nbsp;</td>
    <td width="132">&nbsp;</td>
    <td width="50">&nbsp;</td>
    <td width="203">&nbsp;</td>
<td width="4">&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsBookings);

mysql_free_result($rsClient);
?>

Everything is OK with the database. Maybe the bug is in the Update Record....
PLEASE HELP ANYONE!
THANKS IN ADVANCE!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.