Fallen_angel Posted May 9, 2007 Share Posted May 9, 2007 Hi , I am having a bit of an issue getting a foreach statement i have made to work , essentially what this for each statement is suposed to do is write a row to a database for each one of the check boxes selected here is the code <Form enctype='multipart/form-data' action="process_add_banner.php" method="post"> <input type='hidden' name='send' value='1' /> <tr><td>Name:</td><td><input type="Text" name="name"><br></td></tr> <tr><td>Locations</td><td> <table width="100%"> <tr ><td><INPUT TYPE=CHECKBOX NAME="location[]" VALUE="None">None</td> <td><INPUT TYPE=CHECKBOX NAME="location[]" VALUE="Forums">Fourms</td> <td><INPUT TYPE=CHECKBOX NAME="location[]" VALUE="Extras">Extras</td> <td><INPUT TYPE=CHECKBOX NAME="location[]" VALUE="Portal">Portal</td> </tr> </table> </td><tr> <tr><td></td><td><input type="Submit" name="submit" value="Submit Information"></td><tr> </form> and the processing code is $name=$_POST['name']; $group[]=$_POST['location[]'] ; foreach ($group as $loc) { $sql = "INSERT INTO database (name,group) VALUES ('$name','$loc')"; $result = mysql_query($sql); } Can someone please tell me where i am going wrong ? I don't get any syntax errors it just doesn't do the insert . Thanx allot for your assistance Link to comment https://forums.phpfreaks.com/topic/50575-help-with-foreach-on-checkbox-array/ Share on other sites More sharing options...
Fallen_angel Posted May 9, 2007 Author Share Posted May 9, 2007 I relised that I made an error with my example I gave i put $group[]=$_POST['location[]'] ; instead of just $group=$_POST['location'] ; after doing some more testign i have discovered the issue is when i add a certain feild of my database to the sql script , even if I vet the value manually it still makes the whoel thing fail so the issue is in part of my sql script that I'm sure i can knuckle out thanx anyways hehe Link to comment https://forums.phpfreaks.com/topic/50575-help-with-foreach-on-checkbox-array/#findComment-248665 Share on other sites More sharing options...
Fallen_angel Posted May 9, 2007 Author Share Posted May 9, 2007 Ok figured it out for some reason my script didn';t liek the collom with the name group no matter what i put in there , however as soon as i changed group to grp it worked so go figure lol could someone possibly explain that cause i have the script workign now but i'm kinda scratching my head as to what i did wrong before Link to comment https://forums.phpfreaks.com/topic/50575-help-with-foreach-on-checkbox-array/#findComment-248672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.