mysqli_query()至少需要2个参数,给定1个

时间:2019-04-13 02:16:52

标签: php

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\kios\login_act.php on line 7

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\kios\login_act.php on line 7

这些是在我要登录我的应用程序时出现的...我想 我的代码是这样的:

<?php 
session_start();
include 'admin/config.php';
$uname=$_POST['uname'];
$pass=$_POST['pass'];
$pas=md5($pass);
$query=mysqli_query("select * from admin where uname='$uname' and pass='$pas'")or die(mysqli_error());
if(mysqli_num_rows($query)==1){
    $_SESSION['uname']=$uname;
    header("location:admin/index.php");
}else{
    header("location:index.php?pesan=gagal")or die(mysqli_error());
    // mysqli_error();
}
// echo $pas;
 ?>

1 个答案:

答案 0 :(得分:2)

这仅仅是示例,不能解决您的问题,

  

您错过了第一个参数,例如$con,您需要在其中传递数据库详细信息,例如以下示例:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Perform queries 
mysqli_query($con,"SELECT * FROM Persons");
mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age) 
VALUES ('Glenn','Quagmire',33)");

mysqli_close($con);
?>

您的两个错误都与$con有关,需要在$conmysqli_query($con,$sql);中传递第一个Parma mysqli_error($con);