Jump to content

[SOLVED] UPDATE error


bcraig

Recommended Posts

Can anyone tell me why im getting this error

 

Im using:

PHP 5.2.5

MySql 5.0.45

Apache 2.2.6

Windows XP localhost

 

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 'WHERE id=41' at line 1

 

This is my 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["update"])) && ($_POST["update"] == "updateAuction")) {
  $updateSQL = sprintf("UPDATE auctions SET title=%s, current_price=%s, description=%s, quals=%s, refs=%s, materials=%s, deadline=%s, day=%s, location=%s, payment=%s, WHERE id=%s",
				   GetSQLValueString($_POST['title'], "text"),
				   GetSQLValueString($_POST['current_price'], "int"),
				   GetSQLValueString($_POST['description'], "text"),
				   GetSQLValueString($_POST['quals'], "text"),
				   GetSQLValueString($_POST['refs'], "int"),
				   GetSQLValueString($_POST['materials'], "text"),
				   GetSQLValueString($_POST['deadline'], "date"),
				   GetSQLValueString($_POST['day'], "text"),
				   GetSQLValueString($_POST['location'], "text"),
				   GetSQLValueString($_POST['payment'], "text"),
				   GetSQLValueString($_POST['id'], "int"));
				   
				   

  mysql_select_db($database_jobsnz_conn, $jobsnz_conn);
  $Result1 = mysql_query($updateSQL, $jobsnz_conn) or die(mysql_error());

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

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