警告:mysqli_query()期望参数2是字符串,对象在C:wampwww中给出


Warning: mysqli_query() expects parameter 2 to be string, object given in C:wampwww

当我尝试这段代码时,我收到关于第二个参数到字符串的警告。我在之前类似的问题中看到过一些答案,但我没有找到解决方案…据我所知,问题是if语句??谢谢。

if (isset($_GET['id'])) {
    $str_id = $_GET['id'];
    ($conn->set_charset("utf8"));   
    if ($result=mysqli_query($conn, $q )) {
        while ($obj=mysqli_fetch_object($result)) {
        }
?>
<?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();
  }
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
  {
  while ($obj=mysqli_fetch_object($result))
    {
    printf("%s (%s)'n",$obj->Lastname,$obj->Age);
    }
  // Free result set
  mysqli_free_result($result);
}
mysqli_close($con);
?>