PHP mySqli 未更新 table
PHP mySqli not updating table
我正在尝试更新 table 但没有任何变化。数据库名称和字段正确。
<?php
require("config.php");
$forname = $_POST['name'];
$newval = "yes";
mysqli_query($con, "UPDATE pupils SET signin = '$newval' WHERE forname = '$forname'");
mysqli_close($con);
?>
帮助感谢!
谢谢,
更新
似乎由于某种原因数据没有正确发布。
<form class="form-inline" name="markin" role="form" method="POST" action="markin.php">
<div class="form-group">
<select class="form-control" name"name" id="name">
<?php
$query = "SELECT * FROM `pupils` WHERE signin = 'no'";//Grab the data
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {//Creates a loop to loop through results
echo "<option>" . $row['forname'] . "</option>";//$row['index'] the index here is a field name
}
?>
</select>
</div>
<button type="submit" class="btn btn-success">Mark in</button>
</form>
首先,我建议您阅读 prepared statements quickstart guide 这会引导您进行类似的操作...
$stmt = $con->prepare('UPDATE pupils SET signin = ? WHERE forname = ?');
$stmt->bind_param('ss', $newval, $forname);
$stmt->execute();
作为额外的好处,您应该设置 mysqli 以在错误时抛出异常,这样您就不必一直检查 return 值。在您的 config.php
文件中,在创建连接之前,执行此操作...
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = new mysqli(...); // or however you create $con
如评论中所述,开发环境中的 php.ini
文件应使用以下指令启用完整的错误报告
error_reporting = E_ALL
display_errors = On
要直接回答您的问题,您缺少 <select>
元素 name
属性的等号。应该是
<select class="form-control" name="name" id="name">
我正在尝试更新 table 但没有任何变化。数据库名称和字段正确。
<?php
require("config.php");
$forname = $_POST['name'];
$newval = "yes";
mysqli_query($con, "UPDATE pupils SET signin = '$newval' WHERE forname = '$forname'");
mysqli_close($con);
?>
帮助感谢! 谢谢,
更新
似乎由于某种原因数据没有正确发布。
<form class="form-inline" name="markin" role="form" method="POST" action="markin.php">
<div class="form-group">
<select class="form-control" name"name" id="name">
<?php
$query = "SELECT * FROM `pupils` WHERE signin = 'no'";//Grab the data
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {//Creates a loop to loop through results
echo "<option>" . $row['forname'] . "</option>";//$row['index'] the index here is a field name
}
?>
</select>
</div>
<button type="submit" class="btn btn-success">Mark in</button>
</form>
首先,我建议您阅读 prepared statements quickstart guide 这会引导您进行类似的操作...
$stmt = $con->prepare('UPDATE pupils SET signin = ? WHERE forname = ?');
$stmt->bind_param('ss', $newval, $forname);
$stmt->execute();
作为额外的好处,您应该设置 mysqli 以在错误时抛出异常,这样您就不必一直检查 return 值。在您的 config.php
文件中,在创建连接之前,执行此操作...
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = new mysqli(...); // or however you create $con
如评论中所述,开发环境中的 php.ini
文件应使用以下指令启用完整的错误报告
error_reporting = E_ALL
display_errors = On
要直接回答您的问题,您缺少 <select>
元素 name
属性的等号。应该是
<select class="form-control" name="name" id="name">