警告:mysqli_query()期望给定参数1为mysqli布尔值 [英] Warning: mysqli_query() expects parameter 1 to be mysqli boolean given

查看:80
本文介绍了警告:mysqli_query()期望给定参数1为mysqli布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过表单提交某些内容后,我得到了欢迎部分,然后出现了mysql连接错误,因为mysql已关闭,当我打开它时它消失了,然后是布尔错误. 警告:mysqli_query()期望参数1为mysqli,第25行的C:\ xampp \ htdocs \ welcome.php中给出的布尔值"

After submitting something through my form I get the welcome part and then the mysql connection error because mysql is off, it goes away when I turn it on and then the boolean error. "Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\welcome.php on line 25"

<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>

推荐答案

很可能您在mysqli_connect中遇到连接错误.凭据错误或MySQL关闭.

Most probably, you have a connection error in mysqli_connect. Wrong credentials or MySQL is down.

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();
}

这篇关于警告:mysqli_query()期望给定参数1为mysqli布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆