Py学习  »  DATABASE

如何获取所有广播组的信息?有5个组,我有一个PHP脚本将它们处理到MySQL数据库

williseed • 4 年前 • 242 次点击  

我正在进行一项民意调查,看看谁会赢得这场战斗。我把信息发送到我网站上的数据库。所有的表单都是将数据库上选定的单选按钮(fighter)增加1。有五组(每组2名战士)供人员选择。 每次我到我的网站上提交所有的五个单选按钮,它只增加一个“Fighter5”为我选择的单选按钮,但所有其他4组不会得到更新(无论我选择哪一个战斗机)。我可以在mysql中看到fighter5的值增加了一个,但其他值保持为零。

HTML代码:

<div class= "container">
        <section id = "predictions">
           <div class = "row">
              <div class = "column1">
               <h1>Most Popular Fights</h1>

                Conor Mcgregregor vs Khabib Nurmag. 2
                <form action ="predictions.php" method="POST">
                  <input type = "radio" name = "fighter1" value = "Conor McGregor"> Conor
                  <input type = "radio" name = "fighter1" value = "Khabib Nurmagomedov"> Khabib
                  <br><br>
                  Georges St‑Pierre vs Tyron Woodley <br>
                  <input type = "radio" name = "fighter2" value = "Georges St‑Pierre"> GSP
                  <input type = "radio" name = "fighter2" value = "Tyron Woodley"> Woodley
                  <br><br>
                  Israel Adesanya vs Kelvin Gastelum <br>
                  <input type = "radio" name = "fighter3" value = " Israel Andesanya"> Andesanya
                  <input type = "radio" name = "fighter3" value = "Kelvin Gastelum"> Gastelum
                  <br><br>
                Francis Ngannou vs Brock Lesnar <br>
                  <input type = "radio" name = "fighter4" value = "Francis Ngannou"> Ngannou
                  <input type = "radio" name = "fighter4" value = "Brock Lesnar"> Lesnar
                  <br><br>
                Nate Diaz vs Tony Ferguson <br>
                  <input type = "radio" name = "fighter5" value = "Nate Diaz"> Nate
                  <input type = "radio" name = "fighter5" value = "Tony Ferguson"> Tony
                  <br>

                <input type = "submit" value = "submit" class = "submit_button">
                </form>
              </div>

PHP代码:

$fighter1 = $_POST["fighter1"];
$fighter2 = $_POST["fighter2"];
$fighter3 = $_POST["fighter3"];
$fighter4 = $_POST["fighter4"];
$fighter5 = $_POST["fighter5"];

/********************** CONNECTION ***********************/
$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error)
    {   die("Connection Failed: " . $conn->connect_error);}

/************************ UPDATES ************************/
if ($fighter1 == "Conor McGregor") 
{   $sql = "UPDATE Predictions_Poll SET fighter_one_votes = fighter_one_votes + 1 WHERE id = 1"; }
else if ($fighter1 == "Khabib Nurmagomedov")
{   $sql = "UPDATE Predictions_Poll SET fighter_two_votes = fighter_two_votes + 1 WHERE id = 1"; }

if ($fighter2 == "Georges St‑Pierre")
{   $sql = "UPDATE Predictions_Poll SET fighter_one_votes = fighter_one_votes + 1 WHERE id = 2"; }
else if ($fighter2 =="Tyron Woodley")
{   $sql = "UPDATE Predictions_Poll SET fighter_two_votes = fighter_two_votes + 1 WHERE id = 2";}

if ($fighter3 == "Israel Adesanya")
{   $sql = "UPDATE Predictions_Poll SET fighter_one_votes = fighter_one_votes + 1 WHERE id = 3"; }
else if ($fighter3 =="Kelvin Gastelum")
{   $sql = "UPDATE Predictions_Poll SET fighter_two_votes = fighter_two_votes + 1 WHERE id = 3"; }

if ($fighter4== "Francis Ngannou")
{   $sql = "UPDATE Predictions_Poll SET fighter_one_votes = fighter_one_votes + 1 WHERE id = 4"; }
else if ($fighter4 ==  "Brock Lesnar")
{   $sql = "UPDATE Predictions_Poll SET fighter_two_votes = fighter_two_votes + 1 WHERE id = 4"; }

if ($fighter5 == "Nate Diaz")
{   $sql ="UPDATE Predictions_Poll SET fighter_one_votes = fighter_one_votes + 1 WHERE id = 5"; }
else if ($fighter5 == "Tony Ferguson")
{   $sql = "UPDATE Predictions_Poll SET fighter_two_votes = fighter_two_votes + 1 WHERE id = 5"; } 

/****************** UPDATE SUCCESS CHECK *******************/
if($conn->query($sql)== true)
    {echo "Record Successfully Updated";}
else
    {echo "Error Updating Record: " . $conn->error;}

    $conn->close();
?>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38301
 
242 次点击