选择菜单将值发送到SQL [英] Select menu send value to SQL
问题描述
你好
i需要在数据库中更新值,通过在选择菜单中选择一个值,我试试这段代码但是没有工作
<?php require_once('../ con / config.php'); ?>
<?php
mysql_select_db($ database_config,$ config);
mysql_query(set names'utf8');
$ query =SELECT * FROM sec1octa;
$ result = mysql_query($ query);
?>
< form method =POSTaction =edit_data.php>
echo< table>;
echo< tr>;
echo< th> id< / th>;
echo< th> name< / th>;
echo< th> status< / th>;
echo< / tr>;
if(mysql_num_rows($ result)> 0){
while($ row = mysql_fetch_array($ result)){
echo< tr>;
echo< td>< input type = \hidden \name = \id [] \value = \{$ row ['stu_no']} \大小= \ 15\ >< / TD>中;
echo< td> {$ row ['stu_name']}< / td>;
echo< td>;
echo< select name = \status [] \>;
echo< option value = \open \> {$ row ['stu_status']}< / option>;
echo< option value = \close \> closee< / option>;
echo< / select>;
echo< / td>;
echo< / tr>;
}
}
?>
< / table>
< input class =buttonstyletype =submitvalue =حفظ>
< / form>
i需要显示选项为'已插入数据库'
和另一个选项。
*更新数据库是可行的,但我询问选择菜单。当我选择选项它的工作和更新数据库并获得价值,但当我在另一行进行任何其他更改时,价值将会改变
i需要2选项1-开放2-关闭
edit_data.php
<?php require_once('../ Con / config.php' ); ?>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< / head>
<?php
mysql_select_db('gohargro_student');
$ db = mysqli_connect(localhost,****,*****,****);
mysql_query(set names'utf8');
if(isset($ _ POST ['id'])){
$ tally = 0;
//构建批量
foreach的所有查询($ _ POST ['id'] as $ index => $ id){
$ queries [] =UPDATE `goh` .sec1octa` SET`stu_status` ='。mysqli_real_escape_string($ db,$ _ POST ['status'] [$ index])。''WHERE`stu_no` ='。mysqli_real_escape_string($ db,$ id ) '。
}
//运行所有查询
if(mysqli_multi_query($ db,implode(';',$ queries))){
do {
$ tally + = mysqli_affected_rows($ db);
} while(mysqli_more_results($ db)&& mysqli_next_result($ db));
}
//评估结果
if($ error_mess = mysqli_error($ db)){
echo语法错误:$ error_mess;
} else {
echo$ tally row,($ tally!= 1?s:),updated;
}
mysqli_close($ con);
}
?>
我的尝试:
尝试添加三个选项(一个已经在数据库中已经有另外两个可供选择但不能正常工作)
database_config,
配置);
mysql_query(set names'utf8');
query =SELECT * FROM sec1octa;
Hello
i need update value in database , by choose a value in select menu , i try this code but didn't work
<?php require_once('../con/config.php'); ?> <?php mysql_select_db($database_config, $config); mysql_query("set names 'utf8'"); $query = "SELECT * FROM sec1octa"; $result = mysql_query($query); ?> <form method="POST" action="edit_data.php"> echo "<table>"; echo "<tr>"; echo "<th>id</th>"; echo "<th>name</th>"; echo "<th>status</th>"; echo "</tr>"; if(mysql_num_rows($result)>0){ while($row=mysql_fetch_array($result)){ echo "<tr>"; echo "<td><input type=\"hidden\" name=\"id[]\" value=\"{$row['stu_no']}\" size=\"15\"></td>"; echo "<td>{$row['stu_name']}</td>"; echo "<td>"; echo "<select name=\"status[]\">"; echo "<option value=\"open\"> {$row['stu_status']} </option>"; echo "<option value=\"close\">closee</option>"; echo "</select>"; echo "</td>"; echo "</tr>"; } } ?> </table> <input class="buttonstyle" type="submit" value="حفظ"> </form>
i need the display option be ' the one has already insert in database '
and another option .
*the update database is work , but i ask about select menu . when i choose option it's work and update database and get value but when i make any another change in another row the value will changed
i need 2 option 1- open 2- close
edit_data.php
<?php require_once('../Con/config.php'); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <?php mysql_select_db('gohargro_student'); $db= mysqli_connect("localhost","****","*****","****"); mysql_query("set names 'utf8'"); if(isset($_POST['id'])){ $tally=0; // build all queries for the batch foreach($_POST['id'] as $index=>$id){ $queries[]="UPDATE `goh`.`sec1octa` SET `stu_status`='".mysqli_real_escape_string($db,$_POST['status'][$index])."' WHERE `stu_no`='".mysqli_real_escape_string($db,$id)."'"; } // run all queries if(mysqli_multi_query($db,implode(';',$queries))) { do{ $tally+=mysqli_affected_rows($db); } while(mysqli_more_results($db) && mysqli_next_result($db)); } // assess the outcome if($error_mess=mysqli_error($db)){ echo "Syntax Error: $error_mess"; }else{ echo "$tally row",($tally!=1?"s":"")," updated"; } mysqli_close($con); } ?>
What I have tried:
try to added three option ( one which has in database already and another 2 to choose but not work )
database_config,
config); mysql_query("set names 'utf8'");
query = "SELECT * FROM sec1octa";
这篇关于选择菜单将值发送到SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!