使用PHP将HTML文本字段中的数据更新到MySQL数据库

使用PHP将HTML文本字段中的数据更新到MySQL数据库,php,mysql,html,Php,Mysql,Html,我尝试使用PHP将HTML文本字段中的数据更新到数据库中。我想更新通知字段。我无法获取SQL查询的文本字段值。这是我的密码: $result = mysql_query($query) or die (mysql_error()); // Run query while($row = mysql_fetch_array($result)) { ?> <tr><td><?php echo $row[0];?></td>

我尝试使用PHP将HTML文本字段中的数据更新到数据库中。我想更新通知字段。我无法获取SQL查询的文本字段值。这是我的密码:

$result = mysql_query($query) or die (mysql_error()); // Run query
    while($row = mysql_fetch_array($result)) { ?> 
        <tr><td><?php echo $row[0];?></td>      
        <td><?php echo $row[1];?></td>
        <td><?php echo $row[2];?></td>
        <td><?php echo $row[3];?></td>
        <td><?php echo $row[4];?></td>
        <td><input type="text" name="notifications" value="<?php echo $row[5];?>" size=13></td></tr>
<?php 
if (isset($_POST['save'])) { 
    for($i = 0; $i < $count; $i++) // For loop
    {
        $id=mysql_result($result,$i,"id"); // Get id from query
        $notifications = $_POST['notifications'];
        $update = "UPDATE testtable SET notifications = {$notifications[$i]} WHERE id = {$id}";
        echo "$update<br>";
        //mysql_query($update); // Run
    } 
$result=mysql\u query($query)或die(mysql\u error());//运行查询
而($row=mysql\u fetch\u array($result)){?>

Notifications字段看起来可能是一个字符串,因此需要使用如下引号对其进行转义:

$update=“updatetesttable SET notifications='{$notifications[$i]}'其中id={$id}”


您的代码很容易受到注入攻击,您应该使用预先准备好的语句,然后转到PDO或msqli,以避免潜在的攻击。

问题已解决。我刚刚在输入类型名称中添加了[],现在它可以工作了。