我是 PHP 新手。我一直在研究一个简单的表单,它将数据提交到 MySQL 数据库并遇到了障碍。我只是不确定代码中的错误在哪里,任何帮助将不胜感激。
<?php
$host = 'localhost'; // hostname
$username = 'root'; // MySQL Username
$password = 'root'; // MySQL Password
$db_name = 'idp'; // Database name
$tbl_name = 'data'; // Table name
// Attempt MySQL Connection
mysql_connect("$host", "$username", "$password")or die("Cannot connect.");
// Attempt database connection
mysql_select_db("$db_name")or die("Cannot select DB.");
$name = $_POST['name'];
$mbr_name = $_POST['mbr_name'];
$mbr_tel = $_POST['mbr_tel'];
$date = $_POST['date'];
$sql = "INSERT INTO $tbl_name(name, mbr_name, mbr_tel, date)VALUES('$name', '$mbr_name', '$mbr_tel', '$date')";
$result = mysql_query($sql);
if($result) {
echo "Entry Successful";
echo "<br>";
echo "<a href='form.php'>Return to Form</a>";
} else {
echo "<strong>Error</strong>";
}
mysql_close();
?>