Page 1 of 1

PHP Array with HTML Form

Posted: Thu Apr 09, 2009 11:38 am
by amitkpt
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi All,

I am using mysql to fetch some data and then putting it in the form. And I am doing it several times using for loop in a single form. Now I am not sure how to send data to submit form. Here is the code I am using.

Code: Select all

for($i=0; $i<$proj_users; $i++)
   { 
 
    echo "<select name='emp_id[]'>";
    
        $result_emp = mysql_query("SELECT * FROM emp_details");
        $num_results_emp = mysql_num_rows($result_emp);
        
    for($x=0; $x <$num_results_emp; $x++)
    {      
        $row_emp = mysql_fetch_array($result_emp);
        echo "<option value='$i'>".$row_emp['emp_f_name']." ".$row['emp_l_name']."</option>"; 
    }
    echo "</select>";
   }

In other page it is

Code: Select all

for ($i=0; $i< count($_POST['emp_id']); $i++)
{
$emp_id_array = addslashes($_POST['emp_id'][$i]);
}
foreach ($emp_id_array as $value)
{
    echo "Value: $value<br />\n";
}

Now I am not able to understand where I am wrong. Because it is giving me error.

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\project\page.php on line 38

Do anyone have idea about this.


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: PHP Array with HTML Form

Posted: Fri Apr 10, 2009 5:55 am
by novice4eva
your select type must be multiple.

Code: Select all

 
echo "<select name='emp_id[]' multiple=\"multiple\">";
 
if it doesn't work, try $_REQUEST in place of $_POST.