mysql - mysqli::query() expects parameter 1 to be string in PHP
Get the solution ↓↓↓I have below Query in my Php, it outputs result but at the same time giving an errormysqli::query() expects parameter 1 to be string
what is wrong in below code
$con = @mysqli_connect("localhost","$dbname","$dbpass","$dbuser");
if (!$con)
{
die('Connect Error: ' . mysqli_connect_error());
}
$sql_uid=$con->prepare("SELECT id From $dtUsi Where mobile_number='$umobile' and user_type='$user_type'");
$stmti = $con->query($sql_uid);
while($rowi = $stmti->fetch_assoc()) {
$ur_id= $rowi['id'];
}
echo $ur_id;
Answer
Solution:
You can't use prepare and query at the same time. You are giving$sql_uid
toquery
function like it's a query string while it isn't. Use one the these approaches.
Either
$con = @mysqli_connect("localhost","$dbname","$dbpass","$dbuser");
if (!$con)
{
die('Connect Error: ' . mysqli_connect_error());
}
$stmti=$con->query("SELECT id From $dtUsi Where mobile_number='$umobile' and user_type='$user_type'");
while($rowi = $stmti->fetch_assoc()) {
$ur_id= $rowi['id'];
}
echo $ur_id;
or
$con = @mysqli_connect("localhost","$dbname","$dbpass","$dbuser");
if (!$con)
{
die('Connect Error: ' . mysqli_connect_error());
}
$stmti=$con->prepare("SELECT id From $dtUsi Where mobile_number='?' and user_type='?'");
$stmt->bind_param("ss", $umobile, $user_type);
$stmt->execute();
while($rowi = $stmti->fetch_assoc()) {
$ur_id= $rowi['id'];
}
echo $ur_id;
These links might be helpful:
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.