多选框仅通过第一个选定字段更新mysql表中的输出 [英] Multiselect box only updates output in mysql table by the first selected field

查看:62
本文介绍了多选框仅通过第一个选定字段更新mysql表中的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好所有:)



我有一个表格应该将数据添加到两个mysql表食谱和recipe_ingredients。后者是一个链接实体。其中一个字段是多选下拉框。当我使用CTRL选择多个托管时,结果只会在下拉框中返回一个选定的选项...我已经在这里工作了几个小时..没有任何建议......我的代码是......



HTML表格



hello all:)

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代码





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



$ db = mysql_select_db(tasteofhome);







$ recipename = $ _ POST ['recipename'];



$ recipeauthor = $ _ POST ['recipeauthor'];



$ cooktime = $ _ POST ['cooktime'];





$阶段= $ _ POST ['阶段'];



$ own = $ _ POST ['owningredients' ];













$ name = $ _ SESSION ['login_user'];





$ sql2 =SELECT user_id from用户user_name ='$ name';

$ q1 = mysql_query($ sql2);





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









$ s =插入食谱(recipe_name,recipe_author,cook_time,stages_description,user_id)值('$ recipename','$ recipeauthor','$ cooktime', $阶段','$ row [0]');

;





$ sql5 = mysql_query($ s);



}

if($ sql5 === FALSE){

die (mysql_error()); // TODO:更好的错误处理

}

if($ sql5)

{





}



else {

echo未插入数据;



}



foreach($ _POST ['Ingredients']作为$ selectedOption){









$ sql =从ingredients_name ='$ selectedOption'的成分中选择ingredients_id;;



$ q = mysql_query($ sql); }



while($ rows = mysql_fetch_array($ q))



{





$ sql3 =从食谱中选择recipe_id,其中recipe_name ='$ recipename';



$ s = mysql_query($ sql3);











echo $ rows [0];



while($ table2 = mysql_fetch_array($ s))



{











$ sql2 =插入recipe_ingredients(ingredients_id,recipe_id)值('$ rows [0]','$ table2 [0]');

$ w = mysql_query($ sql2);

}}

if($ w)

{

echo数据成功输入数据库
;



}







if($ w == true){

header('refresh:2; url = myre cipes.php');



}



?>



返回

推荐答案

q = mysql_connect(localhost ,'root','');


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


db = mysql_select_db(tasteofhome);






db=mysql_select_db("tasteofhome");




recipename =
recipename=


这篇关于多选框仅通过第一个选定字段更新mysql表中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆