Hello all and a Happy New Year to you,
I have searched vigorously through the forum but have not been able to find what might be wrong with my script. I have a form that records the checkbox to a table and I have created another form that will be used to update that information. I get the info from the table and display which checkbox has been checked but then after trying to change the checkbox it does not update.
// link from previous page
// http://localhost/process_signatures_update_edit_gr.php?bid=579
// javascript on this page - checkform(this)
/* // activates the checkbox
var inputs = document.getElementsByTagName('input');
for(var c = 0; c < inputs.length; c++){
if(inputs[c].type == "checkbox" && inputs[c].checked == true){
//alert(inputs[c].value);
array.push(inputs[c].value);
}
}
*/
// bid is a link as shown above - not a submit from the previous page
settype($bid, 'integer');
if(isset($_GET['bid'])) {
$bid=$_GET['bid'];
}
$query = "select candidacy1, candidacy2, candidacy3, candidacy4
from $table_name WHERE bid = '$bid' ";
$result = mysql_query($query)
or die ("Error in query: $query. <br />\
" . mysql_error() . "<br />\
" );
$row = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
// set checkboxes from data
$candidacy1 = $row["candidacy1"];
$candidacy2 = $row["candidacy2"];
$candidacy3 = $row["candidacy3"];
$candidacy4 = $row["candidacy4"];
}
echo '<form action="process_signatures_update_final_gr.php?bid=$bid" method="post" name="form" onsubmit="return checkform(this)" />'." \
";
echo '<input type="hidden" id="candidacy1" name="candidacy1" value="0" />';
echo '<input type="hidden" id="candidacy2" name="candidacy2" value="0" />';
echo '<input type="hidden" id="candidacy3" name="candidacy3" value="0" />';
echo '<input type="hidden" id="candidacy4" name="candidacy4" value="0" />';
// for brevity, I have placed only one of the four inputs here
if ($candidacy1=='1')
{ echo "<input type=\\"checkbox\\" id=\\"candidacy1\\" name=\\"candidacy1\\" value=\\"$candidacy1\\" checked=\\"checked\\" /> \
"; }
else
{ echo "<input type=\\"checkbox\\" id=\\"candidacy1\\" name=\\"candidacy1\\" value=\\"$candidacy1\\" /> \
"; }
echo "If you check this box, your name will appear as "Anonymos"";
echo '<input type="submit" id="mail" name="mail" class="button1" value="- update -" /> ';
if(isset($_POST['mail']))
{
$candidacy1 = remove_headers($_POST['candidacy1']);
$update = "update $table_name set
candidacy1 = '$candidacy1',
WHERE bid = '$bid' ";
$result2 = mysql_query($update) or die(mysql_error());
mysql_query("COMMIT");
} // end isset submit
The expected result would be displayed on the next page.
The rest of the form updates so I guess that the problem has to be specifically with the checkbox.
Peter