Jump to content

[SOLVED] PHP/MySQL Error


kyleldi

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.