【发布时间】:2016-08-16 21:49:58
【问题描述】:
我在 apache 服务器上的 localhost 中使用以下 php 代码,它没有显示任何错误,当我以 html 表单提交数据但数据未保存在 phpmyadmin 表中时,一切似乎都很好。有人可以帮忙吗?
<?php
$servername = 'localhost';
$username = 'root';
$password = 'xxxx';
$database = 'newtable';
$con = mysqli_connect("$servername","$username","$password","$database");
if (! $con){
die('Could not connect: ' . mysqli_error());
}
$sql = "INSERT INTO newtable (firstname, lastname) VALUES ('$_POST[firstname]', '$_POST[lastname]')";
if (! $sql)
{
die('Error: ' . mysqli_error());
}
echo "Record Added Successfully!";
mysqli_close($con);
?>
和html代码是:
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" /><br><br>
Lastname: <input type="text" name="lastname" /><br><br>
<input type="submit" />
</form>
</body>
</html>
【问题讨论】:
-
请回答下面给出的答案。
标签: php mysqli phpmyadmin