我一直在用 PHP 处理一个很小的表单获取和插入到 MySQL 数据库系统。我以前在本地 WAMP 服务器上使这种类型的代码工作,现在我试图在我的主机上真正做到这一点,但我不断收到以下代码的 500 错误内部服务器错误。
HTML:
<!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">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="Main_Stylesheet.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<title>Contact</title>
</head>
<body>
<nav class="navbar navbar-default" id="Body_Nav" style="margin-bottom: none;">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.php">Filosofie in Amsterdam</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar" >
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="bestel.php">Bestel</a></li>
<li><a href="preview.php">Preview</a></li>
<li class="active"><a href="contact.php">Contact</a></li>
<li><a href="us.php">Over Ons</a></li>
<li><a href="donate.php">Doneren</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid" id="Contact_Main_Header">
<div class="row">
<div class="col-lg-12">
<h1 class="text-center" id="Contact_Main_Header_H1">Contact</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-6">
<h2 class="text-center">Informatie</h2>
</div>
<div class="col-lg-6">
<h2 class="text-center">Nieuwsbrief</h2>
<p class="text-justify">Op de hoogte zijn van voortgang of het laatste nieuws? Geef je dan op via de nieuwsbrief hieronder:</p>
<form method="post" action="formvalid.php">
<div class="form-group">
<label for="Contact_Form_Email">Email Adres:</label>
<input type="email" name="Contact_Form_Email" class="form-control" id="Contact_Form_Email" placeholder="Plaats hier je email adres" required>
</div>
<div class="form-group">
<label for="Contact_Form_First_Name">Voornaam:</label>
<input type="text" name="Contact_Form_First_Name" class="form-control" id="Contact_Form_First_Name" placeholder="Plaats hier je voornaam" required>
</div>
<div class="form-group">
<label for="Contact_Form_Last_Name">Achternaam:</label>
<input type="text" name="Contact_Form_Last_Name" class="form-control" id="Contact_Form_Last_Name" placeholder="Plaats hier je voornaam" required>
</div>
<button type="submit" class="btn btn-default">Verzenden</button>
</form>
</div>
</div>
</div>
</body>
</html>
和 PHP:
<?php
$Server = "localhost";
$Username = "filoso1q_admin";
$PW = "Foxtrot15";
$DB = "filoso1q_nieuwsbrief";
$connection = mysqli_connect($Server, $Username, $PW, $DB);
if($connection = false) {
die("Error: " . mysqli_error_connect());
}
$Email = $_POST("Contact_Form_Email");
$First_Name = $_POST("Contact_Form_First_Name");
$Last_Name = $_POST("Contact_Form_Last_Name");
$sql = "INSERT INTO `Users` ('User_ID', 'Email', 'First_Name', 'Last_Name') VALUES (NULL, '$Email', '$First_Name', '$Last_Name');";
mysqli_query($sql);
mysqli_close($connection);
?>
我很确定其中一些应该可以工作,但由于某种原因,我只能在 PHPmyadmin 本身中运行查询。我的主机使用 Cpanel webadmin 作为网络服务器。