php - 如何拒绝在 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 说你必须添加更多细节并写一些关于你的问题的东西,但我没有任何东西要写,这就是为什么我现在正在写一些东西。
解决方案
推荐阅读
- javascript - 在 node.js API 中上传和处理多个文件
- python - 如何将外键ID传递给表单?或将表单链接到外键值 DJango
- php - 如果在 foreach 中不为空,则将变量包含到数组中
- java - 如何构建openCSV CSVReader
- python - 如何从python中的变量中删除某些单词和数字
- reactjs - React Saleor 产品类别
- postgresql - PostgreSQL - 我应该只为其他还没有索引的列创建索引吗?
- amazon-web-services - 上传大约 100 个小文件,S3 事件通知丢失
- python - 如何正确屏蔽卷积神经网络中的值
- python - Python Pip 无法使用 pip 命令识别任何模块