&&youyou 2022-10-04 20:34 采纳率: 100%
浏览 16
已结题

PHP表单提交问题提问


<!DOCTYPE html>

<html>

    <head>
        <meta charset="utf-8" />
        <title>register.php</title>
        <link rel="stylesheet" type="text/css" href="css/register.css" />
    </head>
    <body>
        <div class="register">
            <h2>注册</h2>
            <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"
            onsubmit="upload()">
                <div class="register_flex">
                    <div class="register_flex_box">
                        <input type="text" name="username" placeholder="请注册用户名" />
                    </div>
                    <div class="register_flex_box">
                        <input type="password" name="password" placeholder="请自定义密码" />
                    </div>
                    <div class="register_flex_box">
                        <input type="text" name="tip" placeholder="请自定义密保标题:" />
                    </div>
                    <div class="register_flex_box">
                        <input type="text" name="tip_content" placeholder="请输入密保内容:" />
                    </div>
                    <div class="register_flex_box">
                        <input class="register_button" type="submit" value="注册"/>
                    </div>
                    <div class="register_flex_box">
                        <button class="register_button" name="register" onclick='window.open("04.php")'>登录</button>
                    </div>
                </div>
            </form>
        </div>
        
        <script>
            function upload(){
                <?php
                    $username=$password=$tip=$tip_content="";
                    if($_SERVER["REQUEST_METHOD"]=="POST"){
                        if (empty($_POST["username"])) {
                            echo "<script>alert('username is required!');</script>";
                        } else {
                            $name = check_input($_POST["name"]);
                        }
                        $username=check_input($_POST['username']);
                        $password=check_input($_POST['password']);
                        $tip=check_input($_POST['tip']);
                        $tip_content=check_input($_POST['tip_content']);
                    }
                    function check_input($data) {
                        $data = trim($data);
                        $data = stripslashes($data);
                        $data = htmlspecialchars($data);
                        return $data;
                    }
                    // 连接数据库
                    $con=mysqli_connect("localhost","test_connect_db","YNxb8Tj","test_connect_db");
                    if (!$con) 
                    { 
                        echo "连接 MySQL 失败: " . mysqli_connect_error(); 
                    }
                    $sql="insert into user (username,password,tip,tip_content) values ('$username','$password','$tip','$tip_content')";
                    if (mysqli_query($con, $sql)) {
                        echo "新记录插入成功";
                    } else {
                        echo "Error: " . $sql . "
"
. mysqli_error($con); } mysqli_close($con); ?>
} </script> </body> </html>

PHP提交表单出现一个问题,每次会提交两遍,哪个地方不对啊?

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-10-04 21:01
    关注

    箭头位置的结束大括号放错位置,应该放到最后横线的位置

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 创建了问题 10月4日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改