通过我的表单提交内容后,我得到了欢迎部分,然后是mysql连接错误,因为mysql已关闭,当我打开它然后布尔错误时它会消失。 "警告:mysqli_query()要求参数1为mysqli,在第25行和第34行的C:\ xampp \ htdocs \ welcome.php中给出布尔值;
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?><br>
Your password is <?php echo $_POST["password"]; ?><br>
You have purchased the <?php echo $_POST["sub_type"]; ?>
<?php
$mysqli_host = "localhost";
$mysql_username = "root";
$mysql_password = "123";
$site_db = "test";
$info_name = $_POST["name"];
$info_pass = $_POST["password"];
$info_email = $_POST["password"];
$sub_type = $_POST["sub_type"];
$con=mysqli_connect($mysqli_host,$mysql_username,$mysql_password,$site_db);
// Checks connection to twitch webpanel database and inserts registreation info
if (mysqli_connect_errno());
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO Users (Username, Password, Email, Subcription)
VALUES ('$info_name', '$info_pass', '$info_email', '$sub_type')");
?>
</body>
</html>
答案 0 :(得分:8)
最有可能的是,mysqli_connect中存在连接错误。错误的凭据或MySQL已关闭。
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
//you need to exit the script, if there is an error
exit();
}
答案 1 :(得分:1)
if (mysqli_connect_errno());
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit(); // **this is missing**
}
mysqli_query($con,"INSERT INTO Users (Username, Password, Email, Subcription)
VALUES ('$info_name', '$info_pass', '$info_email', '$sub_type')");
答案 2 :(得分:0)
这是你的错误:
if (mysqli_connect_errno());
最后应该没有分号。
同样根据文档,您应该使用它来检查连接错误:
if (mysqli_connect_error())
但正如我在评论中所说,我建议使用PDO而不是mysqli。并确保正确转义插入数据库的值并使用pbkdf2或scrypt加密密码。