如何處理來自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 –