我是网络开发的新手。在这段代码中,我试图创建一个表单,其中 index.php 中的表单将信息发送到数据库。我的 list.php 应该显示输入的用户列表。但是,我的 index.php 不会将数据发送到数据库。我在 phpMyAdmin 中的数据库绝对是空的。我不知道我的错误可能在哪里。请帮忙。//配置.php
<?php
$dbhost = 'mysql51-031.wc2.dfw1.stabletransit.com';
$dbuser = '549359_sargis';
$dbpass = '*********';
$dbname = '549359_sargis';
$table = 'Contacts';
$connection = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
$select_db = mysql_select_db($dbname,$connection) or die(mysql_error());
?>
// index.php
<!DOCTYPE html>
<hmtl>
<head>
<title>Dashboard</title>
<?php include("config.php"); ?>
<link rel="stylesheet" type="text/css" href = "style.css">
<?php
if(isset($_POST['submit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phonenumber'];
//$date = date('l jS \of F Y h:i:s A');
$sql = "INSERT INTO " . $table . " (firstname, lastname, email, phone_number, timesstamp) VALUES ('$firstname' , '$lastname' , '$email' , '$phonenumber', NOW())";
$query = mysql_query($sql);
if (!$query)
{
die('Error: ' . mysql_error());
}
}
?>
</head>
<body>
<a href="list.php">View List</a><hr/>
<form action="index.php" method = "POST">
<div>
First name: <input type ='text' id='firstname' name='firstname'/><br />
Last name: <input type = 'text' id='lastname' name='lastname'/><br />
Email: <input type = 'text' id='email' name='email'/><br />
Phone Number: <input type = 'text' id='phone_number' name='phonenumber'/><br />
<input type = 'submit' value='Add' />
</div>
</form>
</body>
</html>