如何修复mysqli_error()需要1个参数,0

时间:2016-09-20 16:41:16

标签: php mysql sql

我在登录表单验证中遇到错误,请在代码中提示错误。

1.Php Code。

<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'user');
define('DB_USER','root');
define('DB_PASSWORD','');

$con=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysqli_error());
$db=mysqli_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysqli_error());
/*
$ID = $_POST['user'];
$Password = $_POST['pass'];
*/
function SignIn()
{
session_start();   //starting the session for user profile page
if(!empty($_POST['user']))   //checking the 'user' name which is from Sign-In.html, is it empty or have some text
{
    $query = mysqli_query("SELECT *  FROM man_login where man_username = '$_POST[user]' AND man_password = '$_POST[pass]'") or die(mysqli_error());
    $row = mysqli_fetch_array($query) or die(mysqli_error());
    if(!empty($row['man_username']) AND !empty($row['man_password']))
    {
        $_SESSION['userName'] = $row['pass'];
        echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";

    }
    else
    {
        echo "SORRY... YOU ENTERD WRONG ID AND PASSWORD... PLEASE RETRY...";
    }
}
}
if(isset($_POST['submit']))
{
    SignIn();
}

?>

请提出建议,如果您需要任何其他信息来解决问题。请告诉我。

感谢。

编辑:我收到以下错误。

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\localhost\login_man on line 8

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\localhost\login_man.php on line 8
Failed to connect to MySQL:

1 个答案:

答案 0 :(得分:2)

您需要在host/中传递连接对象作为参数。 所以,你应该写mysqli_error()

mysqli_error($con)写为mysqli_query()

然后你的mysqli_query($con, "SELECT * FROM tableName"); - 你需要反转变量的参数。

参考: