if(isset($_POST 没有正确调用我的提交按钮,我找不到原因

问题描述 投票:0回答:1
    <body>
    <?php

    include("php/config.php");

     if(isset($_POST['submit'])){

       // $username =$_POST['username'];
       // $PASSWORD =$_POST['PASSWORD'];
      //  $title =$_POST['title'];
      //  $first_name =$_POST['first_name'];
     //   $last_name =$_POST['last_name'];
     //   $gender =$_POST['gender'];
     //   $adress1 =$_POST['adress1'];
     //   $postcode =$_POST['postcode'];
        $email = $_POST['email'];
      //  $telephone =$_POST['telephone'];
      //  $profile_blob =$_POST['profile_blob'];


        $verify_query = mysqli_query($con, " SELECT email FROM users WHERE email ='$email'");

        if(mysqli_num_rows($verify_query) != 0 ){
            echo "<div class='message'>
            <p> This email is used, Try another</p>
            </div> <br>";
            echo "<a href ='javascript:self.history.back()' <button class ='btn'> Go Back </button>"; 
        }

        else{
           // mysqli_query($con,"INSERT INTO     users(username,PASSWORD,title,first_name,last_name,gender,adress1,postcode,email,telephone)Values('$username','$PASSWORD','$title','$first_name','$last_name','$gender','$adress1','$postcode','$email','$telephone')")or die("Error Occured");
       mysqli_query($con,"INSERT INTO users(email)Values('$email')")or die("Error Occured");

          echo "<div class='message'>
        <p> Success</p>
        </div> <br>";
        echo "<a href ='index.php' <button class 'btn'> Go Back </button>";
    }
    


}else{

?>

    <nav class="nav-top">
        <img src="images/Logo.PNG" class="logo"> <!--The logo-->
        <ul>
            <li><a href="Main menu.html">RentmyCaravan.io</a></li> <!--The site title, able to be clicked to go back to the main menu-->
        </ul>
        <img src="images/profile photo.PNG" class="user-pic" onclick="toggleMenu()"> <!--Triggers the script to transition to the submenu-->
        <div class="sub-menu-wrap" id="subMenu"> <!--Surounds the submenu-->
            <div class="sub-menu"> <!--The actual submenu-->
                <div class="user-info"> <!--Anything to do with the user like profile pic and username-->
                    <img src="images/profile photo.PNG">
                    <h2>Dannissoepic</h2>
                </div>
                <hr> <!--A break line-->
                <a href="ListView.html" class="sub-menu-link"> <!--Where it links to-->
                    <img src="images/list.PNG"> <!--The image for it-->
                    <p>List view</p> <!--What the user sees-->
                    <span>></span> <!--Makes it look nicer as a line-->
                </a>
                <a href="AddScreen.html" class="sub-menu-link">
                    <img src="images/+.PNG">
                    <p>Add a caravan</p>
                    <span>></span>
                </a>
                <a href="Edit.html" class="sub-menu-link">
                    <img src="images/empty profile.PNG">
                    <p>Profile</p>
                    <span>></span>
                </a>
                <hr>
                <a href="" class="sub-menu-link">
                    <img src="images/setting.PNG">
                    <p>Settings</p>
                    <span>></span>
                </a>
                <a href="Main menu.html" class="sub-menu-link">
                    <img src="images/signout.PNG">
                    <p>Sign out</p>
                    <span>></span>
                </a>
                <hr>
            </div>
        </div>
    </nav>

    <nav class="nav-site-progress">
        <a href="#">Main Menu</a>
        <a href="#">List View</a>
        <hr>
        <br>
      </nav>

 </header>
        
 
    
    <div class="site">
    <div class="box">
    ----Register new user----
    <br><br>
    Username <br>
    <input type="text" id="username" name="username"><br><br>
    Password <br> 
    <input type="text" id="PASSWORD" name="PASSWORD"><br><br>
    Title <br>
    <input type="text" id="title" name="title"><br><br>
    First Name <br>
    <input type="text" id="first_name" name="first_name"><br><br>
    Last Name <br>
    <input type="text" id="last_name" name="last_name"><br><br>

    Gender
    <input type="text" id="gender" name="gender">
    <input type="checkbox" id="fname6.2" name="fname6.2"><br><br>

    Address <br>
    <input type="text" id="adress1" name="adress1"><br><br>
    Postcode <br>
    <input type="text" id="postcode" name="postcode"><br><br>
    Email <br>
    <input type="email" id="email" name="email"><br><br>
    Phone Number <br>
    <input type="tel" id="telephone" name="telephone"><br><br>
    input profile image <br><br>
    <div style="background-color: #c7c9c9; border: 1px solid black; width: 40%; height: 110px;margin-left: auto; margin-right: auto;">
    <input type="image"id ="fname12" name="fname12" style="border-color: black; width: 70px; height: 50px; text-align: center; background-color: white; " value="+"><br><br>
    </div>
    <br><br>
    <input type="submit" name="submit" value="Register" class="btn-secondary">
    

  
    
    </div>
    </div>
<script>
    let subMenu = document.getElementById("subMenu"); //let submenu be called by the id submenu
    function toggleMenu() //The actual function being called
    {
        subMenu.classList.toggle("open-menu"); //toggle the open menu css class
    }
    </script>



   


    <div>
    <?php } ?>
    </div>

</body>

提供的代码主体,我使用了 not (!) 来强制它,并且我知道另一端的代码可以工作。但通过尝试不同的事情,有时我会收到特定字段(例如电子邮件)的未识别关键错误消息,但如果认为这是页面在按钮之前加载请求的结果。

php html web-frontend
1个回答
0
投票

确保您有

form
喜欢

<form method="post" action="yourpage.php">
    Gender
    <input type="text" id="gender" name="gender">
    <input type="checkbox" id="fname6.2" name="fname6.2"><br><br>

    Address <br>
    <input type="text" id="adress1" name="adress1"><br><br>
    Postcode <br>
    <input type="text" id="postcode" name="postcode"><br><br>
    Email <br>
    <input type="email" id="email" name="email"><br><br>
    Phone Number <br>
    <input type="tel" id="telephone" name="telephone"><br><br>
    input profile image <br><br>
    <div style="background-color: #c7c9c9; border: 1px solid black; width: 40%; height: 110px;margin-left: auto; margin-right: auto;">
    <input type="image"id ="fname12" name="fname12" style="border-color: black; width: 70px; height: 50px; text-align: center; background-color: white; " value="+"><br><br>
    </div>
    <br><br>
    <input type="submit" name="submit" value="Register" class="btn-secondary">
</form>

由于您的按钮现在位于

form
内,通过单击它,您的表单将被发布(针对您指定的操作,该操作需要与您想要将请求发送到的终点相匹配,如果它留空为
action=""
那么帖子将针对当前页面,在这种特定情况下您似乎需要该页面)并且由于它的名称为
submit
,因此这将被传递,并且在这种情况下您的
if
应评估为 true。

© www.soinside.com 2019 - 2024. All rights reserved.