Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Ill just explain by showing my code:

if($_POST)
{
for ($records = 1; $records <= $_POST['numberofrecords']; $records++)
    {
    if((!in_array($_POST['user'][$records], $assigned_users, true))||($_POST['user'][$records]==''))    
       {
       $phonePost['user']       = $_POST['user'][$records];
       $phonePost['id']     = $_POST['id'][$records];

       $this->autoprov_model->update_phone_user($phonePost);
       }                        
   else
       {    
       //other actions.....
       }

etc....

$assigned_users is a query listing all IDs currently selected.

the relevant html is

<select name=user[<?=$lines;?>] style="position: relative; right: 120px;" onchange="submitform(this)">
    <?php if($phone['user_id']=='')echo '<option value="">Unassigned</option>'?>
    <?php foreach ($users_list as $user):?>
    <?php if($user['id']==$phone['user'])$selected = 'selected="selected"'; else $selected = '';?>
    <option value="<?=$user['id'];?>" <?=$selected?>><?=$user['name'];?></option>
    <?php endforeach;?>
</select>

Whats happening is that I am posting all kinds of IDs (relevant to the $assigned_user array) but not actually in the array. and also when I post '' (blank) they never get updated and only reach the second section.

I ask here incase I am missing a trick with posting the values as arrays?

share|improve this question
1  
can you show how you formed the html of user input element? –  Raheel Hasan Apr 23 '13 at 14:52
    
also, what is in $assigned_users? –  Raheel Hasan Apr 23 '13 at 14:53
2  
or just do a var_dump($_POST['user']) –  Thomas Clayson Apr 23 '13 at 14:53
2  
why did you start the loop with $records = 1? –  Raheel Hasan Apr 23 '13 at 14:54
1  
normally, it would start from 0 as that is how an Array is. –  Raheel Hasan Apr 23 '13 at 14:58

1 Answer 1

up vote 0 down vote accepted
  1. you should put name in quotes in your select tag. Like this: name="user[<?=$lines;?>]".
  2. $assigned_users should be an array.
  3. check existence with isset($_POST['user'][$records]) instead of comparing it with empty string, or simply try this: if((@in_array($_POST['user'][$records], $assigned_users, true)==false){.
share|improve this answer
    
2. What makes you think its not? –  Jefffrey Apr 23 '13 at 16:18
    
3. No. No. No. Never. ever. use. @ to. suppress. errors. –  Jefffrey Apr 23 '13 at 16:19
    
Thats why I gave the option to use isset() instead !!! –  Raheel Hasan Apr 23 '13 at 20:52
    
Yes Yes Yes - do you work for Danial Brian?!! –  Raheel Hasan Apr 23 '13 at 20:52
    
As an experienced web engineering are you seriously saying yes to the suppression of errors in PHP? –  Jefffrey Apr 24 '13 at 0:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.