Jump to content

Recommended Posts

Hi All,

 

I'm receiving this very odd error when trying to execute my code.  The error is "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".  What I don't understand is, first of all everything looks fine on line 1.  And second, what in my code would cause this to happen?  Heres the chunk of my code that it's flaking out on.  Anyone have any ideas what i've done wrong?  The code is supposed to pull the .php?id=4 from the URL and display that IDs information in the dynamic page below.

 

<?php require_once('admin/connect.php'); ?>
<?php
if (isset($_GET['id'])) { //Page first accessed
	$id =  $_GET['id']; 
} else {  
	if (isset($_POST['id'])) {  //form has been submit
	$id =  $_POST['id'];
}
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
}
}

mysql_select_db($database_staff, $staff);
$query_rs_staff = "SELECT * FROM staffdirectory WHERE id = $id";
$rs_staff = mysql_query($query_rs_staff, $staff) or die(mysql_error());
$row_rs_staff = mysql_fetch_assoc($rs_staff);
$totalRows_rs_staff = mysql_num_rows($rs_staff);

Link to comment
https://forums.phpfreaks.com/topic/62857-solved-phpmysql-error/
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.