SQL and POST requests


SQL and POST requests

如何处理POST请求中的变量?假设我有这样的表,我想更新特定id所在的投票变量。

所以对于代码,我有这个

$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();
?>

更新

<?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();
?>

如果$_POST值不起作用,请尝试回显:

<?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();
?>