GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Dec-2008, 05:52
diesel_ diesel_ is offline
New Member
 
Join Date: Oct 2008
Posts: 6
diesel_ is on a distinguished road

You have an error in your SQL syntax; check the manual that corresponds to your MySQL


I dont get it, heres my code


the area witht the error is the line starting wirh $query_limit_asset
PHP Code:

mysql_select_db($database_dbconnect, $dbconnect);
$query = "SELECT 
            *
           FROM 
             asset 
                "; 
                
$query_limit_asset = sprintf("%s LIMIT %d, %d", $query_asset, $startRow_asset, $maxRows_asset);
$asset = mysql_query($query_limit_asset, $dbconnect) or die(mysql_error());
$row_asset = mysql_fetch_assoc($asset);

if (isset($_GET['totalRows_asset'])) {
  $totalRows_asset = $_GET['totalRows_asset'];
} else {
  $all_asset = mysql_query($query_asset);
  $totalRows_asset = mysql_num_rows($all_asset);
}
$totalPages_asset = ceil($totalRows_asset/$maxRows_asset)-1;

$queryString_asset = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_asset") == false && 
        stristr($param, "totalRows_asset") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_asset = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_asset = sprintf("&totalRows_asset=%d%s", $totalRows_asset, $queryString_asset); 




here is the code in it's entirety
PHP Code:

<?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"] == "form1")) {
  $updateSQL = sprintf("UPDATE asset SET asset_name=%s, category_id=%s, manufacturer_id=%s, model_id=%s, acquired_date=%s, price=%s, condition_id=%s, location_id=%s, contact_id=%s, warranty=%s, retire_date=%s, description=%s, comment=%s, deployment_id=%s WHERE asset_id=%s",
                       GetSQLValueString($_POST['asset_name'], "text"),
                       GetSQLValueString($_POST['category_id'], "int"),
                       GetSQLValueString($_POST['manufacturer_id'], "int"),
                       GetSQLValueString($_POST['model_id'], "int"),
                       GetSQLValueString($_POST['acquired_date'], "text"),
                       GetSQLValueString($_POST['price'], "double"),
                       GetSQLValueString($_POST['condition_id'], "int"),
                       GetSQLValueString($_POST['location_id'], "int"),
                       GetSQLValueString($_POST['contact_id'], "int"),
                       GetSQLValueString($_POST['warranty'], "text"),
                       GetSQLValueString($_POST['retire_date'], "text"),
                       GetSQLValueString($_POST['description'], "text"),
                       GetSQLValueString($_POST['comment'], "text"),
                       GetSQLValueString($_POST['deployment_id'], "int"),
                       GetSQLValueString($_POST['asset_id'], "int"));

  mysql_select_db($database_dbconnect, $dbconnect);
  $Result1 = mysql_query($updateSQL, $dbconnect) or die(mysql_error());
  
}
?>

<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_asset = 1;
$pageNum_asset = 0;
if (isset($_GET['pageNum_asset'])) {
  $pageNum_asset = $_GET['pageNum_asset'];
}
$startRow_asset = $pageNum_asset * $maxRows_asset;



mysql_select_db($database_dbconnect, $dbconnect);
$query = "SELECT 
            *
           FROM 
             asset 
                "; 
                
$query_limit_asset = sprintf("%s LIMIT %d, %d", $query_asset, $startRow_asset, $maxRows_asset);
$asset = mysql_query($query_limit_asset, $dbconnect) or die(mysql_error());
$row_asset = mysql_fetch_assoc($asset);

if (isset($_GET['totalRows_asset'])) {
  $totalRows_asset = $_GET['totalRows_asset'];
} else {
  $all_asset = mysql_query($query_asset);
  $totalRows_asset = mysql_num_rows($all_asset);
}
$totalPages_asset = ceil($totalRows_asset/$maxRows_asset)-1;

$queryString_asset = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_asset") == false && 
        stristr($param, "totalRows_asset") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_asset = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_asset = sprintf("&totalRows_asset=%d%s", $totalRows_asset, $queryString_asset);


mysql_select_db($database_dbconnect, $dbconnect);
$query_manufacturer = "SELECT * FROM manufacturer";
$manufacturer = mysql_query($query_manufacturer, $dbconnect) or die(mysql_error());
$row_manufacturer = mysql_fetch_assoc($manufacturer);
$totalRows_manufacturer = mysql_num_rows($manufacturer);

mysql_select_db($database_dbconnect, $dbconnect);
$query_model = "SELECT *  FROM model";
$model = mysql_query($query_model, $dbconnect) or die(mysql_error());
$row_model = mysql_fetch_assoc($model);
$totalRows_model = mysql_num_rows($model);

mysql_select_db($database_dbconnect, $dbconnect);
$query_condition = "SELECT *  FROM condition";
$condition = mysql_query($query_condition, $dbconnect) or die(mysql_error());
$row_condition = mysql_fetch_assoc($condition);
$totalRows_condition = mysql_num_rows($condition);

mysql_select_db($database_dbconnect, $dbconnect);
$query_deployment = "SELECT *  FROM deployment";
$deployment = mysql_query($query_deployment, $dbconnect) or die(mysql_error());
$row_deployment = mysql_fetch_assoc($deployment);
$totalRows_deployment = mysql_num_rows($deployment);

mysql_select_db($database_dbconnect, $dbconnect);
$query_location = "SELECT * FROM location";
$location = mysql_query($query_location, $dbconnect) or die(mysql_error());
$row_location = mysql_fetch_assoc($location);
$totalRows_location = mysql_num_rows($location);

mysql_select_db($database_dbconnect, $dbconnect);
$query_contact = "SELECT * FROM contact";
$contact = mysql_query($query_contact, $dbconnect) or die(mysql_error());
$row_contact = mysql_fetch_assoc($contact);
$totalRows_contact = mysql_num_rows($contact);

mysql_select_db($database_dbconnect, $dbconnect);
$query_category = "SELECT * FROM category";
$category = mysql_query($query_category, $dbconnect) or die(mysql_error());
$row_category = mysql_fetch_assoc($category);
$totalRows_category = mysql_num_rows($category);
?>

Last edited by LuciWiz : 02-Dec-2008 at 05:54. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 02-Dec-2008, 11:27
TurboPT's Avatar
TurboPT TurboPT is online now
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: You have an error in your SQL syntax; check the manual that corresponds to your MySQL


It seems that only the 'LIMIT' portion of the query is the only part being sent to be queried, and thus, MySQL will complain.

The issue appears to be at this statement:
PHP Code:

$query_limit_asset = sprintf("%s LIMIT %d, %d", $query_asset, $startRow_asset, $maxRows_asset); 


Hint: where is $query_asset ever assigned? I think the intention was to only use $query?

Of course, to truly see what the query's string contains, simply echo the $query_limit_asset variable before the mysql_query() call.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 lyuboe MySQL / PHP Forum 0 11-May-2005 05:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:36.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.