1,105,594 Community Members

Array help.. thanks!

Member Avatar
lastgame2007
Light Poster
27 posts since Jul 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
//time Am
        $a=$_POST[am];
        $a1=$_POST[am_min];

        $tmeAm=$a.':'.$a1;
        //time AM

        //time Pm
        $p=$_POST['pm'];
        $p5=$_POST['pm_mins'];
        $s=':';
        $times=$p.':'.$p5;

        $ttime=$tmeAm.'-'.$times;
        //days
        $days=$_POST['days'];
        for($i=0;$i<count($days);$i++)
        $dd=$days[$i];

        mysql_query("insert into tc_handle set sid='$_POST[###]',
        sub_id='$_POST[lvl]',
        secid='$_POST[secs]',
        section='$g_sec[name]',
        year='$g_sub[year]',
        code='$g_sub[code]',
        date='$cur',
        acad_id='$now[acad_id]',
        time='$ttime',room='$_POST[rm]',
       ** days='$dd'-------------------------- having problem here, it only saves the last checkbox in my form, why is it???**
        ")or die (mysql_error());
        $mess="Assigned Sucessfully!";
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

      here is my form in that checkbox


       <input type="checkbox" name="days[]" id="days[]" value="M"/>
          M
          &nbsp;&nbsp;
          <input type="checkbox" name="days[]" id="days[]"  value="T"/>
          T
          &nbsp;&nbsp;
          <input type="checkbox" name="days[]" id="days[]" value="W"/>
          W
          &nbsp;&nbsp;
          <input type="checkbox" name="days[]"  id="days[]" value="Thu"/>
          Th
          &nbsp;&nbsp;
          <input type="checkbox" name="days[]"  id="days[]" value="Fri"/>

need help urgent! thanks!

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

You haven't explained what you're trying to do, so I have assumed that you want to insert a comma separated lsit of days into your database field.

The reason only the last day is being saved is because you're overwriting the values in your loop on line 18.

Instead, why not try replacing lines 16 - 18 with:

$days = isset($_POST['days']) ? implode(',', $_POST['days']) : '';

R

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article