Php 更新循环中的特定列

Php 更新循环中的特定列,php,html,mysql,Php,Html,Mysql,这是为mysqli\u array\u fetch中的一行更新特定列的正确方法吗?这对我不起作用 <!doctype html> <html> <head> <meta charset="UTF-8"> <title>الرد على التذكرة</title> <style> .table, tr, td {border: 1px solid black; text-align:center} .cont

这是为
mysqli\u array\u fetch
中的一行更新特定列的正确方法吗?这对我不起作用

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>

.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder} 
.inputresponse {resize:none}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php

include 'config.php';



$sql = "SELECT * FROM contact ORDER BY id";

$con->set_charset('utf8');
$users = mysqli_query($con,$sql);

?>
<table class="table">
<?php

while($row = mysqli_fetch_array($users)) {

?>

<form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row[name] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row[ticketnumber] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row[email] ?> </td> 
</tr>
<tr>
<td> <p1>  الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row[subject] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td>  <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php 

if(isset($_POST['send'])){

        $repsonse = $_POST['response'];

        $result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");

        $rst = mysqli_query($con,$result);

if($rst){
    echo "تم الإرسال";

} else {

    echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>

الرد على التذكرة
.table,tr,td{border:1px纯黑色;text align:center}
.contents{position:static}
p1{字体大小:15px;字体重量:粗体}
.inputresponse{resize:none}

您的HTML格式很奇怪,但我认为这应该可以满足您的需要

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {
    border: 1px solid black;
    text-align:center
}
.contents {
    position:static
}
p1 {
    font-size:15px;
    font-weight:bolder
}
.inputresponse {
    resize:none
}
.inputid {
    text-align:center;
    font-size:10px
}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
    <tr>
    <td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
    <tr>
    <tr>
    <td><p1> الإسم </p1></td>
    <tr>
    <td><?php echo $row['name'] ?></td>
    </tr>
    <tr>
    <td><p1> رقم التذكرة</p1></td>
    </tr>
    <tr>
    <td><?php echo $row['ticketnumber'] ?></td>
    </tr>
    <tr>
    <td><p1> الإيميل</p1></td>
    </tr>
    <tr>
    <td><?php echo $row['email'] ?></td>
    </tr>
    <tr>
    <td><p1> الموضوع </p1></td>
    </tr>
    <tr>
    <td><?php echo $row['subject'] ?></td>
    </tr>
    <tr>
    <td><p1> الرد </p1></td>
    </tr>
    <tr>
    <td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
    </tr>
    <tr>
    <td><input type="submit" value="إرسال" name="send"></td>
    </tr>
    </form>
    <?php 
}
?>
    </table>
<?php
    if(isset($_POST['send'])){
        $response = $_POST['response'];
        $result = "UPDATE contact SET response = ? WHERE id= ?";
        $rst = mysqli_prepare($con,$result);
        mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
        mysqli_stmt_execute($rst);
        if($rst){
            echo "تم الإرسال";
        } else {
            echo " لم يتم الإرسال";
            echo mysqli_stmt_error($rst);
        }
    }
?>
</div>
</body>
</html>

الرد على التذكرة
.表,tr,td{
边框:1px纯黑;
文本对齐:居中
}
.目录{
位置:静态
}
p1{
字体大小:15px;
字体大小:粗体
}
.输入响应{
调整大小:无
}
.输入{
文本对齐:居中;
字体大小:10px
}
رقم التذكرة
الإيميل
الموضوع 
الرد 
变化/潜在改进:

  • 使用准备好的语句代替内联值
  • 已将更新移到
    之外,而
    循环中,因为它不相关
  • 将关闭
    窗体
    标记移动到
    while
    循环中。正如你们制作了多个表单,但每个表单都是第一个表单的孩子,因为它从未关闭过
  • p1
    s看起来像是标题?如果是这样,它们应该在循环之外
  • 如果要在已更新的行旁边显示消息,可以将整个更新过程移到页面过程之前。将其分配给变量,将状态分配给变量,然后在输出中,当您在该记录上时,也输出消息
  • 您的表行似乎关闭不正确

  • id
    放入输入字段。这也将对SQL注入开放。数组的索引也应该被引用
    $row['name']
    。你也应该检查错误。我按照你说的做了,没有任何改变!!当{}时,我是否必须更新内部查询?将问题更新为您所做的。我编辑了我的问题。请仅包括代码的相关部分。这很难阅读。更新查询如何知道要更新它的行是什么?来自
    表单的
    $\u POST['id']
    。我的意思是我必须写什么?内部更新查询?应按原样设置。驱动程序将值添加到查询中;这就是mysqli stmt bind参数所做的。有关更多信息,请参阅。@mohammad01问题或问题?
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>الرد على التذكرة</title>
    <style>
    .table, tr, td {
        border: 1px solid black;
        text-align:center
    }
    .contents {
        position:static
    }
    p1 {
        font-size:15px;
        font-weight:bolder
    }
    .inputresponse {
        resize:none
    }
    .inputid {
        text-align:center;
        font-size:10px
    }
    </style>
    </head>
    <body class="body">
    <div class="contents" align="right">
    <?php
    include 'config.php';
    $sql = "SELECT * FROM contact ORDER BY id";
    $con->set_charset('utf8');
    $users = mysqli_query($con,$sql);
    ?>
    <table class="table">
    <?php
    while($row = mysqli_fetch_array($users)) {
    ?>
    <form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
        <tr>
        <td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
        <tr>
        <tr>
        <td><p1> الإسم </p1></td>
        <tr>
        <td><?php echo $row['name'] ?></td>
        </tr>
        <tr>
        <td><p1> رقم التذكرة</p1></td>
        </tr>
        <tr>
        <td><?php echo $row['ticketnumber'] ?></td>
        </tr>
        <tr>
        <td><p1> الإيميل</p1></td>
        </tr>
        <tr>
        <td><?php echo $row['email'] ?></td>
        </tr>
        <tr>
        <td><p1> الموضوع </p1></td>
        </tr>
        <tr>
        <td><?php echo $row['subject'] ?></td>
        </tr>
        <tr>
        <td><p1> الرد </p1></td>
        </tr>
        <tr>
        <td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
        </tr>
        <tr>
        <td><input type="submit" value="إرسال" name="send"></td>
        </tr>
        </form>
        <?php 
    }
    ?>
        </table>
    <?php
        if(isset($_POST['send'])){
            $response = $_POST['response'];
            $result = "UPDATE contact SET response = ? WHERE id= ?";
            $rst = mysqli_prepare($con,$result);
            mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
            mysqli_stmt_execute($rst);
            if($rst){
                echo "تم الإرسال";
            } else {
                echo " لم يتم الإرسال";
                echo mysqli_stmt_error($rst);
            }
        }
    ?>
    </div>
    </body>
    </html>