Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating MSQL records with Checkbox

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
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?
 
Hi

You mean the [tt]checkbox[/tt]s and the [tt]submit[/tt] [tt]input[/tt]s are in different [tt]form[/tt]s ? Note that only one [tt]form[/tt] is submitted in one request. If the visitor clicks the button labeled "Submit", then the [tt]form[/tt] form2 will be submitted.

You can do the following trick to submit one [tt]form[/tt] with the other, but personally I would not do it :
Code:
<form action="" [red]onsubmit="document.getElementById('form1').submit(); return false"[/red]>
<input type="submit" value="Submit" />
</form>

Feherke.
 
Thanks, feherke.
I see what you mean about the two forms, but as the DW2004 dialogue box appeared to offered me the option to get the buttom to act on either of the two forms, I tried it.
I can't get your code to work either, I'm afraid.

The problem seem to be that if make the button part of form1 I get a button for every checkbox. I want one button that sends the data from a load of checkboxes. Can it be done?
 
I'm coming to see that I'm way off-beam with this idea.
Let's drop it. I need to come at it from a different direction, I can see now.
Thanks for your help.
 
BadChough

do not use that dreamweaver function for cleansing data for use in sql. it is flawed (like 90% of the DW built-in functions).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top