首页 > 解决方案 > 如何拒绝在 php 中发帖?

问题描述

我希望我的 PHP 文件不要发布到我实际编写的网站上。如果所有输入都已填写,我如何发布网站?

我的 index.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Form Validation</title>
    <meta name="description" content="The HTML5 Herald">
    <meta name="author" content="SitePoint">
    <style>
        #inp1{
            margin-bottom: 3px;
        }
        #first{
            margin-bottom: 20px;
        }
        #second{
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<section>
    <h1>Php Form Validation</h1>
    <div>
    <form action="post.php" method="post">
        <div id="first">
       Name: <input type="text" name="name" id="inp1" autocomplete="off"><br>
       Email: <input type="text" name="email" id="inp1" autocapitalize="off"><br>
       Password: <input type="password" name="pwd" id="inp1"><br>
       Repeat Passowrd: <input type="password" name="pwdrepeat">
        </div>
        <div id="second">
            Gender:
            <input type="radio" name="gender" value="female">Female
            <input type="radio" name="gender" value="male">Male
            <input type="radio" name="gender" value="other">Other
        </div>
        <button type="submit" name="submit">Submit</button>
        <?php
        if (isset($_POST['submit'])){
            $name = $_POST['name'];
            $email = $_POST['email'];
            $password = $_POST['pwd'];
            $passwordRe = $_POST['pwdrepeat'];
            $gender = $_POST['gender'];
            if (!empty($name) && !empty($email) && !empty($password) && !empty($passwordRe) && !empty($gender)){
                if ($password === $passwordRe){
                    echo "<p style='color:green;'>Successfully submitted!</p>";
                }else{
                    echo "<p style='color: red'>Your password is not equal to the other</p>";
                }
            }else {
                echo "<p>Please fill all the inputs</p>";
            }
        }
        ?>
    </form>
    </div>
</section>
</body>

我认为必须在 PHP 标记之间进行一些编辑:

<?php
        if (isset($_POST['submit'])){
            $name = $_POST['name'];
            $email = $_POST['email'];
            $password = $_POST['pwd'];
            $passwordRe = $_POST['pwdrepeat'];
            $gender = $_POST['gender'];
            if (!empty($name) && !empty($email) && !empty($password) && !empty($passwordRe) && !empty($gender)){
                if ($password === $passwordRe){
                    echo "<p style='color:green;'>Successfully submitted!</p>";
                }else{
                    echo "<p style='color: red'>Your password is not equal to the other</p>";
                }
            }else {
                echo "<p>Please fill all the inputs</p>";
            }
        }
        ?>

我正在开发一个测验应用程序并最近开始使用 PHP,但我不知道如何拒绝在 PHP 中发帖。Stackoverflow 说你必须添加更多细节并写一些关于你的问题的东西,但我没有任何东西要写,这就是为什么我现在正在写一些东西。

标签: phpformspostpdoget

解决方案


推荐阅读