YUSUF KIPROP YUSUF KIPROP - 5 months ago 10
PHP Question

issue with mysqli function

My page displays this error

"mysqli_query() expects at least two parameters, one given on line $result=mysqli_query($connect);"

Here is my code:

mysqli_query($connect,"SELECT
*FROM $tbl_name WHERE phone
='$phone' and
password= '$password'");
$result=mysqli_query($connect);
$count=mysqli_num_rows
($result);
if($count==1){
....}

Answer

you did this

mysqli_query($connect,"SELECT * FROM $tbl_name WHERE phone ='$phone' and  password= '$password'");
$result=mysqli_query($connect);

I think you want to make the query in a variable, then call mysqli_query using that variable..
So the correct way to do this is :

$con = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
$query = "SELECT * FROM $tbl_name WHERE phone ='$phone' and password= '$password'"; mysqli_query($con, $query);

Where $con is your connection string, and $query is your Query string

Comments