0

DBに値を投稿しようとしていますが、何らかの理由でデータが挿入されていません。ビューから返される配列は空ではありません。しかし、クエリは実行されていません。

私の見解の一部:

<?echo form_open_multipart('eva/evluation_questions_value_entry'); ?>

<input type="hidden" name="id" value="<?php echo htmlspecialchars($id) ?>">
<?php  foreach ($info as $row){ 
  echo "<div class='row'>";
  $i=$row->id;
  echo "<div class='firstc'>".$row->id ."</div>";

  echo "<div class='secondc'>".$row->name ."</div>";

  echo  '<input type="hidden" name="training_evaluation_entry_id'.$i.'" value='.$i.'>';
            //some codes
<input id="submit" type="submit" value="Submit" name="Submit">

  </form> 

コントローラー:

    public function evluation_questions_value_entry() {
    $this->load->helper('url');
    $this->load->helper(array('form', 'url'));
    $this->load->model('TrainingEvaluationModel');
    $trainingEvaluation = $this->TrainingEvaluationModel->evluation_questions_value_entry();
}

モデル:

$this->ip_address = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] . '||' . $_SERVER['REMOTE_ADDR'] : $_SERVER['REMOTE_ADDR'];        
$this->created_on = date('Y-m-d H:i:s');
$this->created_by = 101;
$this->updated_on = null;
$this->updated_by = 0;


for ($i = 1; $i <= 13; $i++) {

    $this->training_evaluation_entry_id = $_POST['training_evaluation_entry_id'.$i];
    $this->value = $this->db->escape($_POST['group'.$i]);


    $query = "INSERT INTO training_evaluation_info(training_evaluation_entry_id,value,ip_address,created_by) 
    VALUES($this->training_evaluation_entry_id,$this->value,'$this->ip_address',$this->created_by)";
    if ($this->db->affected_rows()>0)
{
    return TRUE;
}
return FALSE;    

}

エラーは発生せず、データ配列はモデルに適切に渡されますが、なぜDBに挿入されないのですか??

4

1 に答える 1

2

すべてのフィールドをエスケープしないと危険に見える引用はさておき (パラメーター化されたクエリについて学ぶことをお勧めします)。この場合は、単に$query;を設定しています。

$query = "INSERT INTO training_evaluation_info(training_evaluation_entry_id,value,ip_address,created_by) 
VALUES($this->training_evaluation_entry_id,$this->value,'$this->ip_address',$this->created_by)";

...しかし、実際に実行することはありません。

追加する必要があります。

$this->db->query($query);
于 2013-07-21T16:00:38.953 に答える