我刚刚安装了 xampp,但在将数据插入 MySQL 表时遇到问题。我插入的数据没有出现在 phpmyadmin 中。我不确定是什么问题。
任何帮助将不胜感激,这是我的代码:
<html>
<head>
<title>Test</title>
<body>
<form action="test.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit"name="submit" value="submit"/>
</form>
<?php
$host ="localhost";
$username = "***";
$password = "***";
$database = "***";
$table ="persons";
$con = mysql_connect("localhost","***","***");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bucksbug_mesovot", $con);
$sql="INSERT INTO persons (firstname, lastname, age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Data inserted";
mysql_close($con);
?>
</body>
</html>