下面的php代码似乎运行但不保存到数据库中。它简单而又至关重要,足以令人烦恼。
<html>
<body>
<?php
if(isset($_POST['submit'])){
$connect=mysql_connect("localhost","root","root","form2");
if(mysql_connect_error($connect))
{
echo 'Failed to cnnect';
}
$fname=$_POST['fname'];
if(mysql_query("INSERT INTO user(fname) VALUES('$fname')"))
{
echo ' Success';
}else
{
echo ' No good!';
}
}
?>
<form method ="POST">
First name <input type = "text" name = "fname"></input>
<input type = "submit" name = "submit" value ="enter"></input>
</form>
</body>
</html>
出于安全原因,应该何时使用mysqli(因为不推荐使用mysql)以及如何使用它?