Insert selected item from dropdown list?
Posted: Wed Mar 31, 2010 11:36 pm
How to grab selected item from dropdown list, and put into variabel/database?
My code generating this error message, do I really need to use foreach() and htmlentities?
Error message.
[text]Warning: Invalid argument supplied for foreach() in E:\xampp\htdocs\spokat\ongkos.php on line 8[/text]
Code.
Table.
[text]
---------------------------
id | type | cost
---------------------------
1 | Reguler | 50
2 | Express | 70
---------------------------
[/text]
My code generating this error message, do I really need to use foreach() and htmlentities?
Error message.
[text]Warning: Invalid argument supplied for foreach() in E:\xampp\htdocs\spokat\ongkos.php on line 8[/text]
Code.
Code: Select all
<?
include "function.php";
connect();
if(isset($_POST['check']))
{
echo "Cost : ";
foreach($_POST['result'] AS $result){
$result = htmlentities($result);
echo "$result<br />";
}
}
echo "<form name=\"update\" method=\"post\" action=\"$PHP_SELF\">";
echo "<br>Cost :<select name=\"cost\">";
$price = mysql_query("SELECT * FROM price")or die ("Error");
while($result=mysql_fetch_array($price))
{
echo ("
<option value=$result[id]>$result[type] Rp. $result[cost]</option>
");
}
echo "</select>";
echo "<br><br>";
echo "<input type=\"submit\" value=\"Check\" name=\"check\">";
echo "</form>";
?>
[text]
---------------------------
id | type | cost
---------------------------
1 | Reguler | 50
2 | Express | 70
---------------------------
[/text]