gpt4 book ai didi

php - $_POST 网站崩溃

转载 作者:行者123 更新时间:2023-11-28 05:17:11 24 4
gpt4 key购买 nike

我有下面的 php 页面,这是一个带有联系表的保留页面:

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">

<!--<link rel="icon" href="../../favicon.ico">-->


<title>Coming Soon</title>

<!-- Bootstrap -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/bootstrap-theme.css" rel="stylesheet">
<link href="assets/css/font-awesome.css" rel="stylesheet">

<!-- siimple style -->
<link href="assets/css/style.css" rel="stylesheet">

</head>

<body>

<div id="wrapper">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>TEST</h1>
<h2 class="subtitle">We're working hard to improve our website and we'll be ready to launch soon
<h2 class="subtitle">Feel free to contact us below with any enquiries</h2>

<p>

<?php
$name = $_POST["contactname"];
?>

<form class="Contact" method="post" action="">

<label class="alignleft">Name</label>
<input type="text" name="contactname" id="contactname" placeholder="Enter Name">

<label class="alignleft">Email</label>
<input name="Email" placeholder="Email Address">

<label class="alignleft">Enquiry</label>
<textarea name="Enquiry" placeholder="Your enquiry"></textarea><br>

<input id="submit" name="submit" type="submit" value="Submit!" class="btn btn-theme">

</form>

<div class="social">
<a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
<a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
<!--<a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a>
<a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>-->
</div>
</div>

</div>

</div>
</div>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>

</body>
</html>

在 php 部分中,我试图读取输入框的值,但即使只有

$_POST["contactname"]; 

网站返回 500 内部服务器错误。如果我删除该行并替换为简单的:

echo "Test";

然后站点运行并显示“测试”

从输入框中分配变量是否缺少某些内容?

最佳答案

您应该确保已设置 POST 数组的键,然后在显示它们之前先验证您的值,并确保处理错误和无效值!

   if(isset($_POST["contactname"])){
// Do validation, like making sure its not a empty string
if (!empty($_POST["contactname"])) {
echo $_POST["contactname"];
} else {
echo "A validation error";
}
}

同时启用 PHP 错误输出,这将极大地帮助您调试这样的问题:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

并在您的 php.ini 中使用 display_errors = on 使 PHP 显示解析错误。

关于php - $_POST 网站崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43793094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com