AndyB Posted August 26, 2006 Share Posted August 26, 2006 I've a simple application with a database containing four yes/no enum fields. All I want to do is be able to edit their values from a form that displays four checkboxes either checked for yes or unchecked for no. I can read the POSTed value of all checkboxes that are checked, but in order to update the database record, I also need to be able to get the checkboxes which are not checked (or were unchecked in editing).The form code looks like this ...[code] echo "<td>"; echo "<input type='checkbox' value='". $i. "' name='chbox[]'"; if ($row['shift1']=="1") { echo " checked='checked'"; } echo "/>"; $i++; echo "</td>"; echo "<td>"; echo "<input type='checkbox' value='". $i. "' name='chbox[]'"; if ($row['shift2']=="1") { echo " checked='checked'"; } echo "/>"; $i++; echo "</td>"; echo "<td>"; echo "<input type='checkbox' value='". $i. "' name='chbox[]'"; if ($row['shift3']=="1") { echo " checked='checked'"; } echo "/>"; $i++; echo "</td>";[/code]Once POSTed, I need to be able to constuct a simple UPDATE query that looks like:[code]$query = "UPDATE $dbtable SET (shift1,shift2,shift3,shift4) VALUES ( ... whatever goes here ...) WHERE whatever condition ...";[/code]Constructing the query from the $_POST array has me stumped since only checked values are returned by the form. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 26, 2006 Share Posted August 26, 2006 run a loopif($_POST["value"]){$value = "y";}else{$value = "n";}ORHave a default Not Null field as the enumWhere Default is N Quote Link to comment Share on other sites More sharing options...
448191 Posted August 26, 2006 Share Posted August 26, 2006 [quote author=onlyican link=topic=105728.msg422467#msg422467 date=1156613176]run a loopif($_POST["value"]){$value = "y";}else{$value = "n";}ORHave a default Not Null field as the enumWhere Default is N[/quote]Ah, but then you'd still have to know what indexes to check for!You can't use the POST data. Like you said, it only returns the checked values. There is only one solution to this problem: don't.You can not use indexes that don't exist, obviously.One of the things you COULD do, is use 'SHOW FIELDS' to get the possible options, and set any values not in the superglobal to 0. Other options ofcourse include using an external source (textfile, XML), or 'hard-coding' the form options. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.