-
Superman
Update 1 record in a table
Hi all,
Sorry for the long post but Im having a problem with my Database and php Booking form.
My database consists of a table for the USERS and a table for the SESSIONS
The SESSIONS table has 'sessionid','capacity' & 'placesbooked' as the fields.
My booking form has 4 boxes each with a different 'sessionid' in them. Upon 'Submit' i would like php to add '1' to the 'placesbooked' field for all 4 relevant 'sessionids' (This is so that the session radiobutton can become disabled when the session is full) but i dont know how to go about setting this up?
I went into mySQL and typed in:
UPDATE session SET placesbooked = placesbooked +1
WHERE sessionid = 'F1'
This worked correctly and updated the placesbooked record to '1' for the 'F1' sessionid.
Im not sure how to apply this in PHP.
i tried:
Code:
$query1 = "UPDATE session SET placesbooked = placesbooked +1
WHERE sessionid = '$hiddenTA'";
$result = mysql_query($query1)
or die ("Couldn't execute query.");
But no records are updating in the session table.
- I used the 'insert record' feature of dreamweaver to insert other data in the same form so maybe im not putting it in the correct place?
here is the php code so far:
Code:
<?php require_once('Connections/PED_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_PED_MYSQL, $PED_MYSQL);
$Result1 = mysql_query($insertSQL, $PED_MYSQL) or die(mysql_error());
$query1 = "UPDATE session SET placesbooked = placesbooked +1
WHERE sessionid = '$hiddenTA'";
$result = mysql_query($query1)
or die ("Couldn't execute query.");
$insertGoTo = "confirmed.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_PED_MYSQL, $PED_MYSQL);
$query_Recordset1 = "SELECT * FROM `session`";
$Recordset1 = mysql_query($query_Recordset1, $PED_MYSQL) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Would really appreciate help with this,
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|