PDA

View Full Version : Update Multiple Checkbox Array In Database



admin2gd1
09-02-2008, 02:02 PM
I have a form that I allow a user to update there properties details to my website that I am creating and everything shows whats in that property the user posted from before but for 2 sections does not retrieve the data the user had placed.

The form that allowed the user to post this section was serialized using this.

if(isset($_POST['int_features'])){
$int_features = serialize($_POST['int_features']);
}else{
$int_features = "";
}
if(isset($_POST['ext_features'])){
$ext_features = serialize($_POST['ext_features']);
}else{
$ext_features = "";
}

Now I am trying to do the opposite of that and allow the user to update the features the user want.

All I get is the list of the features the user can select to choose but does not have them ticked for the ones the user picked from before.
This is what the data looks like once the user has selected the features.

a:7:{i:0;s:10:"Bread Oven";i:4;s:4:"Cave";i:5;s:7:"Cellier";i:10;s:7:"Cuisine";i:20;s:5:"Patio";i:23;s:10:"Pizza Oven";i:24;s:5:"Porch";}
Here is the code that I have to unserialize the information that needs correcting.


<?php
$sql = mysql_query("SELECT * FROM ".TBL_INT_FEATURES." ORDER BY `int_feature` ASC");
$int_featureNo = 0;
while ($featuresentered = mysql_fetch_array($sql)){
$intfeaturesvalue = $featuresentered['int_feature'];
if(!empty($int_features)){ // if feature already selected show checked
foreach($int_features as $featVal){
if($intfeaturesvalue == $featVal){
$checked = "checked";
}
}
}
echo "<input type='checkbox' name='int_features[".$int_featureNo."]' value='".$intfeaturesvalue."'> <b>".$intfeaturesvalue."</b><hr size=1 color='#efefef'>";
$int_featureNo = $int_featureNo + 1;
$checked = "";
}
?>

This is the same code for EXT FEATURES!

I really need this corrected other wise all it does is empty what was there already and put the word ARRAY instead.

So if any one can help me with this piece of code I would really appreciate it.

Thank you.

admin2gd1
09-08-2008, 08:37 AM
OK I got it to work, so thank you to all that helped me with your tips.

Early Out
09-08-2008, 08:45 AM
OK I got it to work, so thank you to all that helped me with your tips.

I love posters who ask for help, then get snotty when no one responds. Clearly, no one could offer any good suggestions. Does this make you angry? Do you feel that you had some god-given right to get help from other users?

Oh, and thank you for sharing the solution. This will obviously be a great help to anyone else facing the same issue. :rolleyes: