读取时无法在codeigniter中分发项目。它显示出致命错误

问题描述 投票:1回答:2

这里pname []是数据库中输入和列的名称。这表明我不能包含在读取这些记录时使用方括号。那么我该如何解决?我无法将输入名称更改为它是array.if我更改名称则不会存储数组值。帮助我解决此错误因为我无法进入该项目

 <!-- end snippet -->

  <table class="table table-type  " style="text-align:center">
  <thead>
  <tr>
  <th scope="col">Booking ID</th>
  <th scope="col">Train ID</th>
  <th scope="col">Booked By</th>
  <th scope="col">Passengers</th>
  <th scope="col">Origin</th>
  <th scope="col">Destination</th>
  <th scope="col">Date</th>
  <th scope="col">Arrival Time</th>
  <th scope="col">Departure Time</th>
  <th scope="col">Class</th>
  <th scope="col">Paid</th>
  <th scope="col">Action</th>
  </tr>
  </thead>
  <tbody>
  <?php if(count($booked)):?>
  <?php foreach($booked as $book): ?>
  <tr class="table-type">
  <td><?php echo $book->booking_id; ?></td>
  <td><?php echo $book->train_id; ?></td>
  <td><?php echo $book->booked_by; ?></td>
  <td><?php echo $book->pname[]; ?></td>
  <td><?php echo $book->origin; ?></td>
  <td><?php echo $book->destination; ?></td>
  <td><?php echo $book->date; ?></td>
  <td><?php echo $book->arrivaltime; ?></td>
  <td><?php echo $book->departuretime; ?></td>
  <td><?php echo $book->class; ?></td>
  <td><b><?php echo $book->tamount; ?></b> by&nbsp;<?php echo $book->cardtype; ?>&nbsp;Card</td>
  <td>
  <?php echo anchor("admin/deletetrain/{$book->train_id}",'Delete',['class'=>'btn btn-outline- danger','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
  </td>

</tr>
<?php endforeach;?>
<?php else:?>
<tr>
  <td></td>
  <td></td>
  <td></td>
  <td><h4>NO Trains Available!!</h4></td>
  <td></td>
  <td></td>
  <td></td>
</tr>
<?php endif;?>
</tbody>

COntroller

        public function reserve_train($train_id)
       {
        $this->load->model('user_model');
        $this->form_validation->set_rules('passenger_id', 'Passenger ID', 'required');
        $this->form_validation->set_rules('booked_by', 'Booked by', 'required');
        $this->form_validation->set_rules('pname[]', 'Passenger Name', 'required');
        $this->form_validation->set_rules('age[]', 'Age', 'required');
        $this->form_validation->set_rules('gender[]', 'Gender', 'required');
        $this->form_validation->set_rules('train_id', 'Train ID', 'required');
        $this->form_validation->set_rules('origin', 'Origin', 'required');
        $this->form_validation->set_rules('destination', 'Destination', 'required');
        $this->form_validation->set_rules('date', 'Date', 'required');
        $this->form_validation->set_rules('arrivaltime', 'ArrivalTime', 'required');
        $this->form_validation->set_rules('departuretime', 'DepartureTime', 'required');
        $this->form_validation->set_rules('class', 'Class', 'required');
        $this->form_validation->set_rules('price', 'Price', 'required');
        $this->form_validation->set_rules('ano', 'No.of Adults', 'required|max_length[1]');
        $this->form_validation->set_rules('cno', 'No.of Children', 'required|max_length[1]');
        $this->form_validation->set_rules('tamount', 'Total Amount', 'required');
        $this->form_validation->set_rules('cardno', 'Card Number', 'required|min_length[16]|max_length[16]');
        $this->form_validation->set_rules('noc', 'Name on card', 'required|trim|alpha_numeric_spaces');
        $this->form_validation->set_rules('month', 'Month', 'required');
        $this->form_validation->set_rules('year', 'Year', 'required');
        $this->form_validation->set_rules('cardtype', 'Card Type', 'required');
        $this->form_validation->set_rules('cvv', 'CVV', 'required|min_length[3]|max_length[3]');
        $this->form_validation->set_error_delimiters('<p class="text-danger">','</p>');

        $data=$this->user_model->fetchdata($this->session->userdata('passenger_id'));
        if($this->form_validation->run()){
           // $data=$this->input->post();
           //if($this->input->post()){
            $pname=implode(", ", $this->input->post('pname[]'));
            $age=implode(", ", $this->input->post('age[]'));
            $gender=implode(",", $this->input->post('gender[]'));
            $data= array(
                'passenger_id'=>$this->input->post('passenger_id'),
                'booked_by'=>$this->input->post('booked_by'),
                'pname[]'=> $pname ,
                'age[]'=>$age ,
                'gender[]'=> $gender,
                'train_id'=>$this->input->post('train_id'),
                'origin'=>$this->input->post('origin'),
                'destination'=>$this->input->post('destination'),
                'date'=>$this->input->post('date'),
                'arrivaltime'=>$this->input->post('arrivaltime'),
                'departuretime'=>$this->input->post('departuretime'),
                'class'=>$this->input->post('class'),
                'price'=>$this->input->post('price'),
                'ano'=>$this->input->post('ano'),
                'cno'=>$this->input->post('cno'),
                'tamount'=>$this->input->post('tamount'),
                'cardno'=>$this->input->post('cardno'),
                'noc'=>$this->input->post('noc'),
                'month'=>$this->input->post('month'),
                'year'=>$this->input->post('year'),
                'cardtype'=>$this->input->post('cardtype'),
                'cvv'=>sha1($this->input->post('cvv')),
            );
            $this->load->model('user_model');
            if($this->user_model->reserve($data,$train_id)){

                $this->session->set_flashdata('message','Train booked successfully');
                return redirect("user/ticket");
            }
            else{
                $this->session->set_flashdata('message','Failed to Book Train');
                  }return redirect("user/reserve/{$train_id}");
           }else{
            $this->reserve($train_id);
          }

          }

Here is the view image

mysql codeigniter codeigniter-3
2个回答
0
投票

好吧,所以看到代码后,我认为您的数据已正确保存,但是检索时遇到了麻烦。


0
投票
echo '
'; print_r($book)行之后写foreach($booked as $book):,您可以检查pname格式。这将帮助您以正确的方式显示pname
© www.soinside.com 2019 - 2024. All rights reserved.