Jump to content

Update function not working correctly?


biggieuk

Recommended Posts

Hi,

Im having problems when trying to UPDATE a record in my mysql database.

The php form sends data to the database ok but i want the update query to add 1 to the 'placesbooked' column where 'sessionid' = the value in 'hiddenTA'.

I receive the following error:

Parse error: parse error in /u2/WWW/htdocs/pesdc/confirmation.php on line 59


Here is my code:

[code]
<?php require_once('Connections/PESDC_MYSQL.php'); ?>
<?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_insert"])) && ($_POST["MM_insert"] == "booking")) {
  $insertSQL = sprintf("INSERT INTO students (id, TA, TP, FA, FP, forename, surname, email, course, `year`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['id'], "int"),
                      GetSQLValueString($_POST['hiddenTA'], "text"),
                      GetSQLValueString($_POST['hiddenTP'], "text"),
                      GetSQLValueString($_POST['hiddenFA'], "text"),
                      GetSQLValueString($_POST['hiddenFP'], "text"),
                      GetSQLValueString($_POST['hiddenforename'], "text"),
                      GetSQLValueString($_POST['hiddensurname'], "text"),
                      GetSQLValueString($_POST['hiddenemail'], "text"),
                      GetSQLValueString($_POST['hiddencourse'], "text"),
                      GetSQLValueString($_POST['hiddenhiddenyear'], "int"));
 

  mysql_select_db($database_PESDC_MYSQL, $PESDC_MYSQL);
  $Result1 = mysql_query($insertSQL, $PESDC_MYSQL) or die(mysql_error());
 
  $insertGoTo = "confirmed.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "booking")) {
$updateSQL = sprintf("UPDATE session SET placesbooked =%s, WHERE sessionid =%s"),
            GetSQLValueString($_POST['+1'], "int"),
            GetSQLValueString($_POST['hiddenTA'], "text"));
                   
 

  mysql_select_db($database_PESDC_MYSQL, $PESDC_MYSQL);
  $Result2 = mysql_query($updateSQL, $PESDC_MYSQL) or die(mysql_error());
}

mysql_select_db($database_PESDC_MYSQL, $PESDC_MYSQL);
$query_Recordset1 = "SELECT * FROM `session`";
$Recordset1 = mysql_query($query_Recordset1, $PESDC_MYSQL) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
[/code]

Thanks for any help with this!

Link to comment
Share on other sites

I managed to get this working but still need a little help.

What is the correct syntax for this:

[code]
<?php
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "booking")) {
  $updateSQL = sprintf("UPDATE session SET placesbooked= placesbooked +1 WHERE sessionid=%s,",
                      GetSQLValueString($_POST['hiddenTA'], "text"),
?>
[/code]

To add 1 to the table where session id = more than 'hiddenTA'?

I tried:

[code]
<?php
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "booking")) {
  $updateSQL = sprintf("UPDATE session SET placesbooked= placesbooked +1 WHERE sessionid=%s,%s,%s,%s",
                      GetSQLValueString($_POST['hiddenTA'], "text"),
      GetSQLValueString($_POST['hiddenTP'], "text"),
      GetSQLValueString($_POST['hiddenFA'], "text"),
      GetSQLValueString($_POST['hiddenFP'], "text"));
?>
[/code]

But get an error  :(


Error:  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 'T8'',''T20'',''F7'',''F20''' at line 1
Thanks.
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.