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
https://forums.phpfreaks.com/topic/27854-update-function-not-working-correctly/
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.
I added the IN clause but get the error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /u2/WWW/htdocs/pesdc/confirmation.php on line 36


EDIT:
Fixed this, forgot the " at the end of the IN statement  ;)

Thanks for your help.


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.