dongxin1980 2015-01-26 08:47
浏览 33

多选框仅通过第一个选定字段更新mysql表中的输出

I have a form that supposed to add data to two mysql tables recipes and recipe_ingredients. The latter which is a link entity. One of the fields in the form a multiselect drop down box. When i use CTRL to select multiple entrys the results only return one chosen options in the drop down box...i have been at this for hours..any sugguestions..here is my code

HTML FORM

<table class="form_table">
<tr><form method="POST" onSubmit action="thankyou.php">
</tr><tr>
<td class="ctable_row">Recipe Name:</td>
<td class="ctable_row"><input type="text" name="recipename"></td></tr>
<tr>
<td class="ctable_row">Recipe Author:</td>
<td class="ctable_row"><input type="text" name="recipeauthor"></td>
</tr>
<tr>
<td class="ctable_row">Cook Time (hh:mm:ss): </td>
<td class="ctable_row"><input type="text" name="cooktime"></td>
</tr>
<tr>
<td class="ctable_row">Select From A List of Ingredients<br/>(**hold CTRL to ``select<br/> multiple values**)</td>
<td class="ctable_row"><select multiple="multiple" name="Ingredients[]">
    <option value="Broccoli">Broccoli</option>
    <option value="Carrots">Carrots</option>
    <option value="Cheese">Cheese</option>
    <option value="Macaroni">Macaroni</option>
    <option value="Oil">Oil</option>
    <option value="Flour">Flour</option>
    <option value="Eggs">Eggs</option>
    <option value="Eggs">Chicken</option>
</select>
</select></td></tr>
<tr>
<td class="ctable_row">Recipe Stages</td>
<td colspan="2"><textarea rows="20" cols="65" name="stages">
 Input Recipe Stages here...
</textarea>
<input type="submit" value="Submit">
</td></tr>
</form>
 </div>
</td>

PHP CODE

session_start(); $q=mysql_connect("localhost",'root','');

$db=mysql_select_db("tasteofhome");



$recipename=$_POST['recipename'];

$recipeauthor=$_POST['recipeauthor'];

$cooktime=$_POST['cooktime'];


$stages=$_POST['stages'];


$name=$_SESSION['login_user'];


$sql2="SELECT user_id from users where user_name='$name'";
$q1=mysql_query($sql2);


while ($row=mysql_fetch_array($q1)){



$s="insert into recipes (recipe_name,recipe_author,cook_time,stages_description,user_id)values('$recipename','$recipeauthor','$cooktime','$stages','$row[0]');
";


$sql5=mysql_query($s);

}
if($sql5 === FALSE) { 
die(mysql_error()); // TODO: better error handling
}
if($sql5)
{


}

else {
echo "data not inserted";

}

foreach ($_POST['Ingredients'] as $selectedOption){


$sql="select ingredients_id from ingredients where ingredients_name='$selectedOption' ";

$q=mysql_query($sql); }

while ($rows = mysql_fetch_array ($q))

{

$sql3="select recipe_id from recipes where recipe_name='$recipename' ";

$s=mysql_query($sql3);



echo $rows[0]   ;

while ($table2=mysql_fetch_array($s))

{



$sql2="insert into recipe_ingredients (ingredients_id,recipe_id)values('$rows[0]','$table2[0]')";
$w=mysql_query($sql2);
}}
if($w)
{
echo "Data succesfully entered in the database
";

}


if($w == true){
header ('refresh:2;url=myrecipes.php');

}

?>

Back 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度