Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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:任何用户输入字段和提交按钮仅更新最后一个字段_Php_Html_Mysql - Fatal编程技术网

Php:任何用户输入字段和提交按钮仅更新最后一个字段

Php:任何用户输入字段和提交按钮仅更新最后一个字段,php,html,mysql,Php,Html,Mysql,请原谅我把事情搞砸了…第一次发帖 问题: 我希望它遍历数据库,然后: 分配一张便条 状态(单选按钮) 提交按钮 对于表中列出的每个用户 PBM:每当我试图对任何用户进行更改时,它只会更新表上的最后一个用户,并且不一致地更新注释 我只想让它更新表中该行中的1个特定用户 如果有更多 有效的或预先包装的方法来做这件事我洗耳恭听。我会的 还是想知道我做错了什么。我知道这是 目前sql易受攻击的代码,但为了简单起见, 输入未经过消毒 <head> <link rel=

请原谅我把事情搞砸了…第一次发帖

问题:

我希望它遍历数据库,然后:

  • 分配一张便条
  • 状态(单选按钮)
  • 提交按钮
对于表中列出的每个用户

PBM:每当我试图对任何用户进行更改时,它只会更新表上的最后一个用户,并且不一致地更新注释

我只想让它更新表中该行中的1个特定用户

如果有更多 有效的或预先包装的方法来做这件事我洗耳恭听。我会的 还是想知道我做错了什么。我知道这是 目前sql易受攻击的代码,但为了简单起见, 输入未经过消毒

    <head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css"
</head>
<h1>In Out Board</h1>
<?php
$conn = new mysqli('xxxx', 'xxx', 'xxx', 'xxxxx');

if ($conn->connect_error) {
    die("connection failed: " . $conn->connect_error);
}

if (isset($_GET['submit'])) {
    $idkey = $_GET['idkey'];
    $Status = $_GET['status'];
    $Notes = $_GET['notes'];
    $query = "update InOutUsers set status='$Status', Notes='$Notes'where idkey='$idkey'";
    $result = mysqli_query($conn, $query) or die(mysqli_error());
}

$sql = "SELECT Name, Status, Notes, idkey FROM InOutUsers";
$result = $conn->query($sql);
echo '<table><thead><form>';
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo '<tr>';
        echo '<td>' . $row["Name"] . '</td>';
        echo '<td>' . $row["Status"] . '</td>';
        echo '<td>' . $row["Notes"] . '</td>';
        echo "<input type='hidden' name='idkey' value='{$row['idkey']}' />";
        echo '
        <td style="width: 100px"><input type="radio" name="status" value="In" >In
            <input type="radio" name="status" value="Out" >Out </td>';
        echo '<td>Status: <input type="text" name="notes" placeholder="Where are you going?"></td>';
        echo '<td>';
        echo "<input type='submit' name='submit' value='update'/>";
        echo '</td>';


        echo '</tr>';
        echo '<br>';
    }
}
echo '</form></thead></table>';

我对编程和使用堆栈交换相当陌生,所以如果我做错了,请随时向我提出建议。我担心这件事很简单,但我不能对它掉以轻心。

首先,我想欢迎您来到Stackoverflow和编程世界。 请在下面找到工作代码

<head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css"
</head>
<h1>In Out Board</h1>
<?php
$conn = new mysqli('xxxx', 'xxxx', 'xxxx', 'xxxx');

if ($conn->connect_error) {
    die("connection failed: " . $conn->connect_error);
}

if (isset($_GET['submit'])) {
    $idkey = $_GET['idkey'];
    $Status = $_GET['status'];
    $Notes = $_GET['notes'];
    $query = "update InOutUsers set status='$Status', Notes='$Notes'where idkey='$idkey'";
    $result = mysqli_query($conn, $query) or die(mysqli_error());
}

$sql = "SELECT Name, Status, Notes, idkey FROM InOutUsers";
$result = $conn->query($sql);
echo '<table><thead>';
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo '<form><tr>';
        echo '<td>' . $row["Name"] . '</td>';
        echo '<td>' . $row["Status"] . '</td>';
        echo '<td>' . $row["Notes"] . '</td>';
        echo "<input type='hidden' name='idkey' value='{$row['idkey']}' />";
        echo '
        <td style="width: 100px"><input type="radio" name="status" value="In" >In
            <input type="radio" name="status" value="Out" >Out </td>';
        echo '<td>Status: <input type="text" name="notes" placeholder="Where are you going?"></td>';
        echo '<td>';
        echo "<input type='submit' name='submit' value='update'/>";
        echo '</td>';


        echo '</tr></form>';
        echo '<br>';
    }
}
echo '</thead></table>';


您正在创建具有相同名称的多个输入类型。你应该像@jagad89那样做你是说我应该用foreach替换while循环吗?谢谢!我知道这一定很简单。有时你只是盯着代码看太久,看不见它。
<head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css"
</head>
<h1>In Out Board</h1>
<?php
$conn = new mysqli('xxxx', 'xxxx', 'xxxx', 'xxxx');

if ($conn->connect_error) {
    die("connection failed: " . $conn->connect_error);
}

if (isset($_GET['submit'])) {
    $idkey = $_GET['idkey'];
    $Status = $_GET['status'];
    $Notes = $_GET['notes'];
    $query = "update InOutUsers set status='$Status', Notes='$Notes'where idkey='$idkey'";
    $result = mysqli_query($conn, $query) or die(mysqli_error());
}

$sql = "SELECT Name, Status, Notes, idkey FROM InOutUsers";
$result = $conn->query($sql);
echo '<table><thead>';
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo '<form><tr>';
        echo '<td>' . $row["Name"] . '</td>';
        echo '<td>' . $row["Status"] . '</td>';
        echo '<td>' . $row["Notes"] . '</td>';
        echo "<input type='hidden' name='idkey' value='{$row['idkey']}' />";
        echo '
        <td style="width: 100px"><input type="radio" name="status" value="In" >In
            <input type="radio" name="status" value="Out" >Out </td>';
        echo '<td>Status: <input type="text" name="notes" placeholder="Where are you going?"></td>';
        echo '<td>';
        echo "<input type='submit' name='submit' value='update'/>";
        echo '</td>';


        echo '</tr></form>';
        echo '<br>';
    }
}
echo '</thead></table>';