我在 Ubuntu 上安装了 lamp,一切正常在数据库中,它也不会在 mysql 连接上给出错误。 使用POST方法发送表单数据
<form action="form.php" method="POST">
<label>Email:</label>
<input type="text" name="name">
<label>Password</label>
<input type="password" name="pass">
</form>
这是php代码
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "hello I am here !<br/>";
$con=mysqli_connect("localhost","root","123","login");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$name = $_POST['name'];
$password = $_POST['pass'];
echo " Name: ".$name." <br/>Password: ".$password;
mysqli_query($con,"INSERT INTO login_data (username, password) VALUES ('". $name ."', '". $password ."')");
//it doesnt insert the data
//how do i check the error of that query ?
mysqli_close($con);
?>
帮助!
最佳答案
$sql="INSERT INTO login_data(username,password) values(".$_POST['name'].",".$_POST['password'].")";
mysqli_query(mysqli $link, string $query
)
先连接,再查询。并使用 mysqli
$a=mysqli_query($con, $sql );
关于php - MySQL 连接不工作 Ubuntu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000784/