Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php页面中编辑sql数据_Php_Sql_Select_Edit_Display - Fatal编程技术网

在php页面中编辑sql数据

在php页面中编辑sql数据,php,sql,select,edit,display,Php,Sql,Select,Edit,Display,我需要使用提交的数据编辑我的数据库表 表格如下: mysql_query("set names 'utf8'"); $query = "SELECT * FROM sec1octa"; $result = mysql_query($query); ?> <div align="center"> <form method="get" action="edit_data.php"> <table width="104" border="

我需要使用提交的数据编辑我的数据库表

表格如下:

mysql_query("set names 'utf8'");

$query = "SELECT * FROM sec1octa"; 
$result = mysql_query($query);
?>
<div align="center">
    <form method="get" action="edit_data.php">
        <table width="104" border="1" class="center1">
            <tr>
                <th width="94">first</th>
                <th width="94">second</th>
                <th width="94">status</th>
            </tr>
            <tr>
                <?php
                if (mysql_num_rows($result) > 0) {
                    while ($row = mysql_fetch_array($result)) {
                        ?>
                        <tr>
                            <td><input type="text" name="id" value="<?php echo $row ['stu_no']; ?> " size=10></td>
                            <td><input type="text" name="name" value="<?php echo $row ['stu_name']; ?> " size=10></td> 
                            <td><?php 
                                echo '<select name="status">';   {
                                    echo '<option value="open">'.$row['stu_status'].'</option>';
                                    echo '<option value="close">'.prevent.'</option>';
                                }
                                echo '</select>';
                            ?></td>
                        </tr>
                        <?php
                    }
                }
                ?>
            </tr>
        </table>
        <input type="submit" name="submit"  value="done" />
    </form>

之所以只获取
edit_data.php
$\u GET
中的最后一个值,是因为没有将输入/选择名称设置为数组

<input type="text" name="id" value="some_stu_no">

您的输入错误是:$qeury而不是$query。并分享您的错误。没有错误出现,它只是在我的数据库中的2列中进行更新,最后一列(第42列)和第40列(第40列),当我尝试更新到另一列时,也会更新到第20列42@mickmackusa,请问我该怎么清洗,另外,我如何使用edit_data.php中的名称字段?还是没用?@mickmackusa非常感谢,完成了。我在等,如果有人能帮我写这段代码,让它工作谢谢你,我试图用php制作表单,但我做不到,我也使用你写的代码,但我发现语法错误,无法更正,如果打扰你,我很抱歉。现在它的工作谢谢你,但我可以做提交按钮给所有人吗?不是一个接一个,我想这更容易,选择选项怎么样?有什么想法吗?因为这是不好的,但我先要求解决所有字段的一个更新按钮的问题,然后你做一个逐个更新的字段,所以谢谢你,但这不是我首先要求的,很清楚。但是谢谢你的努力,我已经收回了我的旗帜。快凌晨1点了,我一定是疯了/累了。我已经为您完成了几乎所有的工作,我希望您会奖励我的答案绿色勾号和向上投票,以感谢我的帮助。我不能投票支持(低于15个代表),但谢谢您,当我达到15个代表时,我会投票支持,
<input type="text" name="id" value="some_stu_no">
<input type="text" name="id[]" value="some_stu_no">
<form method="POST" action="edit_data.php">
....
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=\"text\" name=\"id[]\" value=\"{$row['stu_no']}\" size=\"10\"></td>";
            echo "<td>{$row['stu_name']}</td>"; 
            echo "<td>";
                echo "<select name=\"status[]\">";  // I don't like your option set up here, but I don't fully understand it either.
                    echo "<option value=\"open\">{$row['stu_status']}</option>";
                    echo "<option value=\"close\">.prevent.</option>";
                echo "</select>";
            echo "</td>";
        echo "</tr>";
    }
}
....
<input type="submit" value="Submit All">
</form>
// create a mysqli connection called $db

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);
}