Home » Php » Passing variables in a PHP Query

Passing variables in a PHP Query

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to pass a URL as a url parameter in php but when I try to get this parameter I get nothing but his error:

Parse error: syntax error, unexpected ‘$mysqli_qry’ (T_VARIABLE) in C:\xampp\htdocs\getUserDash.php on line 6

I’m using the following url form: http://localhost/getUserDash.php?username=aleksandra

this is my php query:

<?php
require "connection.php";

$username = $_GET['username'] 

$mysqli_qry = "select * from user_details where username like '$username'";

$result = mysqli_query($conn,$mysqli_qry);
if(mysqli_num_rows($result) > 0)
{
    if($mysqli_qry)
    {
        while($row=mysqli_fetch_array($result))
        {
            $user_details[] = $row;
        }
        print(json_encode($user_details));
    }
}
else
{
    echo "failure";
}

?>
How to&Answers:

This code worked for me; replaced $username = $_GET[‘username’] to $username = $_GET[‘username’];

 <?php
 require "connection.php";

 $username = $_GET['username'];

 $mysqli_qry = "select * from wfa_user where Name like '$username'";

 $result = mysqli_query($conn,$mysqli_qry);
 if(mysqli_num_rows($result) > 0)
 {
 if($mysqli_qry)
 {
    while($row=mysqli_fetch_array($result))
    {
        $user_details[] = $row;
    }
    print(json_encode($user_details));
}
 }
 else
 {
echo "failure";
 }

 ?>