Using Dreamweaver2004 to write my code I have attempted to set up a page where the same SMALLINT Field of all the records of a MYSQL table are Updated with the use of a Checkbox and Submit Button.
The Records are listed using a Repeat Region Server Behaviour, each with its own Checkbox. Initially the Checkboxes are checked or not according to the existing entry ("1" or "0") on the database. That bit works fine, but the reords are not being updated when I make a change to the boxes and submit. Here is relevant the 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 chk_sixmonth SET ck_tosend=%s WHERE ck_organisation=%s",
GetSQLValueString(isset($_POST['ck_tosend']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['hiddenField'], "text"));
Here is the Checkbox Form code:
<form action="<?php echo $editFormAction; ?>" name="form1" id="form1" method="POST">
<input name="ck_tosend" type="checkbox" id="ck_tosend" value="checkbox" <?php if (!(strcmp($row_rstSix['ck_tosend'],"1"))) {echo "checked";} ?> />
<input name="hiddenField" type="hidden" value="<?php echo $row_rstSix['ck_organisation']; ?>" />
<input type="hidden" name="MM_update" value="form1">
</form>
and the Button
<form name="form2" id="form2" method="post" action="">
<input type="submit" name="Submit" value="Submit" />
</form>
Can someone kindly advise as to how to get it to function, please?
The Records are listed using a Repeat Region Server Behaviour, each with its own Checkbox. Initially the Checkboxes are checked or not according to the existing entry ("1" or "0") on the database. That bit works fine, but the reords are not being updated when I make a change to the boxes and submit. Here is relevant the 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 chk_sixmonth SET ck_tosend=%s WHERE ck_organisation=%s",
GetSQLValueString(isset($_POST['ck_tosend']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['hiddenField'], "text"));
Here is the Checkbox Form code:
<form action="<?php echo $editFormAction; ?>" name="form1" id="form1" method="POST">
<input name="ck_tosend" type="checkbox" id="ck_tosend" value="checkbox" <?php if (!(strcmp($row_rstSix['ck_tosend'],"1"))) {echo "checked";} ?> />
<input name="hiddenField" type="hidden" value="<?php echo $row_rstSix['ck_organisation']; ?>" />
<input type="hidden" name="MM_update" value="form1">
</form>
and the Button
<form name="form2" id="form2" method="post" action="">
<input type="submit" name="Submit" value="Submit" />
</form>
Can someone kindly advise as to how to get it to function, please?