PHP Array with HTML Form

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
amitkpt
Forum Newbie
Posts: 2
Joined: Thu Jul 24, 2008 1:21 pm

PHP Array with HTML Form

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: PHP Array with HTML Form

Post 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.
Post Reply