如何处理来自POST请求的变量?可以说我有像this这样的表格而且我想更新票据变量,无论具体的id是什么。SQL和POST请求
所以对于代码,我有这个
$vote = $_POST["votes"];
$sentid = $_POST["sentid"];
一起
像这样的东西
UPDATE `my_exampleo202s`.`President Candidates` SET votes = votes + 1 WHERE `President Candidates`.`id` = sentid
而且在发布请求我与一些发送sentid。 sentid = 3
虽然这不起作用。我无法提供任何错误或任何内容,因为我没有从浏览器中查看它。
任何想法什么是我应该这样做的正确方法?
(这是我现在所拥有的,如果需要这种耐心的代码)
<?php
$vote = $_POST["votes"];
$sentid = $_POST["sentid"];
$conn = new mysqli("localhost","exampleo202s","","my_exampleo202s");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE `my_exampleo202s`.`President Candidates` SET votes = votes + 1 WHERE `President Candidates`.`id` = sentid";
if ($conn->query($sql) === TRUE) {
echo "<br>Record updated successfully <br>";
} else {
echo "<br>Error updating record: <br>" . $conn->error;
}
$conn->close();
?>
UPDATE
<?php
$vote = $_POST["votes"];
$sentid = $_POST["sentid"];
$conn = new mysqli("localhost","jusavoting10rxx9s3","","my_jusavoting10rxx9s3");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE `my_jusavoting10rxx9s3`.`President Candidates` SET votes = votes + 1 WHERE `President Candidates`.`id` = $sentid";
if ($conn->query($sql) === TRUE) {
echo "<br>Record updated successfully <br>";
} else {
echo "<br>Error updating record: <br>" . $conn->error;
}
$conn->close();
?>
'\'my_exampleo202s \'。\'总统候选人\''看起来不像一个合适的表名。你的数据库是什么样的?无论您是否使用浏览器,您仍然可以将'$ conn-> error'记录到外部文件。 –
你应该使用[mysqli_real_escape_string()](http://php.net/manual/en/mysqli.real-escape-string.php) –
在你的查询中应该是$ sentid –