Update Field In The Table

[b]Hello,

i want to update field in the table but i can’t[/b]

that’s the code which i did in controller :


if (isset($_POST['pids']) and $_POST['opt'] == 'modifier') {

            $i = 0;

            foreach ($_POST['pids'] as $pid) {

                $i++;

                $ser = clic_user::model()->findByPk($id);

                $ser->p_number = $_POST['p_numbers']; 

                $ser->save();

            }

            $_SESSION['msg'] = "<br><div class='alert'>" . $i . ' contacts modifie;s </div><br>';

        }

and my code in view is :


<form id="frm_user" method="post">

<table class="dataGrid" style=" min-width:700px; width:auto; margin:auto;">

  <tr>

	<th><input type="checkbox" id="checkall" /></th>

    <th><?php echo $sort->link('p_nom'); ?></th>

    <th><?php echo $sort->link('p_number'); ?></th>

    

  </tr>

  <?php foreach($clic_userList as $n=>$model): ?>

  <tr class="<?php echo $n%2?'even':'odd';?>">

    <td><input type="checkbox"  value="<?php echo $model->pid;?>" name="pids[]" class="pids"/></td>

    <td style="text-align:center"><?php echo CHtml::encode($model->p_nom); ?></td>

    <td><input type="text" value="<?php echo CHtml::encode($model->p_number); ?>" name="p_numbers" id="p_numbers"/>

    <input type="submit" value="Modifier" class="btn_form"  id="modifier"   name="modifier" /></td>


  </tr>

</table>


<?php if($_GET['type']!="ajax"){ ?>

 <table style="width:710px; margin:auto;">

<tr><td style="text-align:left">

<input type="hidden"  id="opt" value="" name="opt"/>

<input type="submit" value="Supprimer" class="btn_form"  id="supprimer"   name="supprimer" />

<input type="submit" value="Modifier" class="btn_form"  id="modifier"   name="modifier" />


</td></tr>

</table></form>

1508

modification.png

Please help me, really i neeeeeeeeed your helps.

And Thanks for all


          $ser = clic_user::model()->findByPk($id);

                $ser->p_number = $_POST['p_numbers']; 

                $ser->save();



By the code above, it says that,

Fetch the result.

You need to have it as , for save


          

                $ser-for-save =new clic_user;

                $ser-for-save =$ser;  

                $ser-for-save ->save();



first check if your model is valid then do saving operation




 $ser = clic_user::model()->findByPk($id);

 $ser->p_number = $_POST['p_numbers']; 

  if ($ser->validate()) {

     $ser->save();

  } else { 

   echo $ser->getErrors();

  }



Thanks friend, i did that but i got then the value of last field, not the value wich i posted.

can you help me friend ?

Check you form




<tr class="<?php echo $n%2?'even':'odd';?>">

    <td><input type="checkbox"  value="<?php echo $model->pid;?>" name="pids[]" class="pids"/></td>

    <td style="text-align:center"><?php echo CHtml::encode($model->p_nom); ?></td>

    <td><input type="text" value="<?php echo CHtml::encode($model->p_number); ?>" name="p_numbers[b][<?php echo $model->pid;?>][/b]" id="p_numbers"/>

    <input type="submit" value="Modifier" class="btn_form"  id="modifier"   name="modifier" /></td>




in you model




 $ser->p_number = $_POST['p_numbers'][$id]; 



Thanks friend, really i got the result.

Thank youuuuuu