We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,389 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Array help.. thanks!

//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!

2
Contributors
1
Reply
19 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
lastgame2007
Light Poster
27 posts since Jul 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 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

blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0655 seconds using 2.67MB