Jump to content

Query was empty?? Only when include is used?


Rabastan

Recommended Posts

In the following code, when I load the page into my browser everything works fine. However when I include it in its div I get an error. I dont get it??

 

The error i get is "Query was empty"

 

Here is the code, Like I said I ohnly get the error when I include the page in the site. If I load it on its own it works fine.

 

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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 = $_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 todo SET updated=NOW(), completed=%s WHERE id=%s",
                       GetSQLValueString(isset($_POST['completed']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_sitterlink, $sitterlink);
  $Result1 = mysql_query($updateSQL, $sitterlink) or die(mysql_error());

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

$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 todo SET completed=%s WHERE id=%s,",
                       GetSQLValueString(isset($_POST['completed']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['id'], "int"));
				   


  mysql_select_db($database_sitterlink, $sitterlink);
  $Result1 = mysql_query($updateSQL, $sitterlink) or die(mysql_error());

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

?>
<?php do { ?>
  <table width="100%" border="0">
    <tr>
      <td><?php echo $row_todopend['id']; ?></td>
    </tr>
    <tr>
      <td><?php echo $row_todopend['created']; ?></td>
    </tr>
    <tr>
      <td><?php echo $row_todopend['name']; ?></td>
    </tr>
    <tr>
      <td><?php echo $row_todopend['desc']; ?></td>
    </tr>
    <tr>
      <td> </td>
    </tr>
    <tr>
      <td> 
        <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
          <table align="center">
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Completed:</td>
              <td><input type="checkbox" name="completed" value=""  <?php if (!(strcmp(htmlentities($row_todopend['completed'], ENT_COMPAT, ''),"Y"))) {echo "checked=\"checked\"";} ?> /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right"> </td>
              <td><input type="submit" value="Update record" /></td>
            </tr>
          </table>
          <input type="hidden" name="id" value="<?php echo $row_todopend['id']; ?>" />
          <input type="hidden" name="MM_update" value="form1" />
          <input type="hidden" name="id" value="<?php echo $row_todopend['id']; ?>" />
        </form>
      <p> </p></td>
    </tr>
    <tr>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
    </tr>
  </table>
  <?php } while ($row_todopend = mysql_fetch_assoc($todopend)); ?>
<?php
mysql_free_result($todopend);
?>

Link to comment
Share on other sites

That error occurs when the variable being put into the mysql_query() statement is empty/doesn't exist.

 

You need to pin down exactly which query is failing on your combined page. For us to help with a problem on your combined page, you would need to post all the code needed to reproduce that combined page.

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.