Jump to content

Recommended Posts

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

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 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.