Welcome Guest, Not a member yet? Register   Sign In
Need Help With Form Submission
#1

[eluser]vincej[/eluser]
Hi - Can someone PLEASE help me figure out how to get my data into my Database from my form ?? I have a CI Form which allows the user to amend and then submit the dates and locations. It looks like this:

Code:
Pick Up ID  Location         Date 1     Date 2    Date 3  Date 4  Remove?
1            Canmore         1 April  1 May 1 June   1 July  Delete


In order to facilitate easy searches and DB management the Dates Table looks like this:


Code:
puid  locationid  dates
1       1            1331668779
15       1            1383668779
12       1            1311746700
5       1            1321746641
16       2            1381668779
9       2            1331746700

Every date falls within the same DB column.

Using Group_CONCAT in the query and EXPLODE in the view , It all works very well for pivoting the dates into a horizontal display.

The resulting array which feeds the form looks like this:

Code:
Array
(
    [0] => Array
        (
            [location] => Banff
            [locationid] => 1
            [TheDates] => 1311746700,1321746641,1331668779,1383668779
        )

    [1] => Array
        (
            [location] => Canmore
            [locationid] => 3
            [TheDates] => 1311746700,1321746641,1331746641,1371668779
        )

    [2] => Array
        (
            [location] => Collingwood
            [locationid] => 4
            [TheDates] => 1311746700,1321746641,1331746641,1371668779
        )
As you can see TheDates for each location is held in a comma delimited string. They are exploded out such that they can be placed into the view using this code:

View

Code:
foreach ($pickupdates as $item) {
   $theDates = explode(',', $item['TheDates']);
  ?>
<tr align="center">
  <td width="100" align="center">&lt;?php echo  $item['locationid'];?&gt;</td>
    <td width="100" align="center">&lt;?php $data = array('name'=>$item['location'], 'size'=>20,'value' => $item['location']); echo form_input($data); ?&gt;</td>
    <td width="100">&lt;?php $data = array('name'=>$theDates[0],'size'=>15,'value' =>(strftime("%a %d %b %Y",$theDates[0]))); echo form_input($data); ?&gt;</td>
    <td width="100">&lt;?php $data = array('name'=>$theDates[1],'size'=>15,'value' =>(strftime("%a %d %b %Y",$theDates[1]))); echo form_input($data); ?&gt;</td>
    <td width="100">&lt;?php $data = array('name'=>$theDates[2],'size'=>15,'value' => (strftime("%a %d %b %Y",$theDates[2]))); echo form_input($data); ?&gt;</td>
    <td width="100">&lt;?php $data = array('name'=> $theDates[3],'size'=>15,'value' => (strftime("%a %d %b %Y",$theDates[3]))); echo form_input($data); ?&gt;</td>
    <td width="150"> &lt;?php echo anchor('admin/pickup_detail/deletelocation/'. $item['location'], 'Delete');?&gt;</td>

  </tr>
&lt;?php  ;} ?&gt;

</table>

At this point things stop working properly. I know that my model does not work and is flawed. I get an error saying invalid argument of the 'Foreach' in the model code below. I am not sure how to properly construct the $Data array in the CI form so that my update controller and update model amend the fields correctly bearing in mind the nature of the data structures and the fact that it is being presented in a converted Human readable date yet stored as date stamps.


Controller:


Code:
function Updatelocation(){
  $this->MPickup->Updatelocation();
redirect('admin/pickup_detail','refresh');
}


Model

Code:
function Updatelocation(){
  if( isset( $_POST['locationid'] ) ) {
   foreach( $_POST['locationid'] as $pickupid=>$location) {// ERROR; "Invalid Arguement provide in Foreach"
    $data = array(
  'locationid' => db_clean($_POST['locationid']),
  'dates' => db_clean($_POST['$theDates[0]']),
  'dates' => db_clean($_POST['$theDates[1]']),
  'dates' => db_clean($_POST['$theDates[2]']),
  'dates' => db_clean($_POST['$theDates[3]']),
    );
   $this->db->where('locationid', $locationid);
    $this->db->update('pudates',$data);
  $this->session->set_flashdata('message', 'Table Updated');
   }
   }
   else echo "Update Failed";
  
  }


If ANY ONE can provide me a steer in the right direction I will be forever grateful !!

Many Thanks !!




Messages In This Thread
Need Help With Form Submission - by El Forum - 03-19-2012, 11:43 AM
Need Help With Form Submission - by El Forum - 03-19-2012, 12:56 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 03:00 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 03:33 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 03:40 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 04:03 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 04:15 PM
Need Help With Form Submission - by El Forum - 03-19-2012, 04:44 PM
Need Help With Form Submission - by El Forum - 03-20-2012, 12:26 PM
Need Help With Form Submission - by El Forum - 03-20-2012, 12:48 PM
Need Help With Form Submission - by El Forum - 03-20-2012, 02:06 PM
Need Help With Form Submission - by El Forum - 03-20-2012, 02:15 PM
Need Help With Form Submission - by El Forum - 03-21-2012, 01:30 PM
Need Help With Form Submission - by El Forum - 03-21-2012, 03:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB