How to submit the required values ​​​​to the database using html key switches
@无痕
@无痕 2021-10-13 10:29:39
0
5
929
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <style type="text/css">
        body>div{height: 40px;}
        label{
            display: inline-block;
            width: 50px; height: 22px; background:#dc3545; border-radius: 30px ; transition: background-color .6s linear;
        }
        /*在标签的前面插入一小圆形*/
        label::after{
            content: "关";width: 17px; height: 17px; background-color:#FFFFFF;color:#dc3545;display: inline-block;text-align: center;line-height: 17px;position: relative;left:3px;
            transition: transform.6s linear; border-radius: 50%;
        }
        /*获得复选框后面的第一个兄弟元素label*/
        input[type=checkbox]:checked+label{
            background-color:#28a745;
        }
        input[type=checkbox]:checked+label::after{
            content: "开";color:#28a745;transform: translate(27px);/*向右移动27px*/
        }
    </style>
</head>
<body>
    <form action="1.php" method="post" >
    

        <input  name="yfkg" type="submit"  value="yfkg" onclick="submit"($yfkg=000)>         

        <input name="tfkg" type="submit" value="tfkg" onclick="submit"($tfkg=000)>         

</form> </html>   ```php <?php     header("Content-type: text/html; charset=utf-8");     //建立数据库连接*/     $servername = 'localhost';     $username ='root';     $password = '123';     $dbname = "nongyedapeng";     $conn = new mysqli($servername, $username, $password, $dbname);     function execute_sql($link, $database, $sql){          mysqli_select_db($link, $database)          or die("打开数据库失败: " . mysqli_error($link));          $result = mysqli_query($link, $sql);          return $result;          }            switch ($_POST["submit"]){ case "yfkg":     if ($conn){          $sql = "UPDATE control SET yfkg=111";          $conn1= execute_sql($conn, "nongyedapeng", $sql);          echo "

设计阈值成功

";         }     else{         echo "

请重新输入

";         }     break; case "tfkg":     if ($conn){          $sql = "UPDATE control SET yfkg=000";          $conn1= execute_sql($conn, "nongyedapeng", $sql);          echo "

设计阈值成功

";         }     else{         echo "

请重新输入

";         }     break; default: } ?>

@无痕
@无痕

reply all(2)
A _ Q _i_

Your PHP code cannot be executed at all. There are errors in your link data. Do you have classes? Why do you need new mysqli? Besides, the function you use to connect to the database is wrong. It is mysqli_connect()

逆旅行人

You probably want to fill in the data in the form and then submit the data in the form to the database through a button, right?

image.png

According to your code, you need to create a new 1.php in the html directory and put your php code into it

  • reply Just pass $_GET['corresponding name in the form']
    autoload author 2021-10-13 21:40:16
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template