php - mySQL 语法错误

标签 php mysql

   <html>
<head><title> InpatientList </title><head>
<body>

<h1> InpatientList </h1>


<?php
$conn = mysqli_connect("127.0.0.1","root","root","");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$q1 = mysqli_query($conn," select * from joseph.inpatient_1501003f");
if ($q1 = mysqli_query($conn,"Query String")) {

  while ($r1 = mysqli_fetch_row($q1)) {
    for ($k=0; $k<count($r1); $k++){    
      print htmlspecialchars($r1[$k]). " : ";   
   }    
   print "<BR>";    
  };

} else {
  printf("Errormessage: %s\n", mysqli_error($conn));
}

mysqli_close($conn);

?>
</body>
</html>

我收到此错误,内容为

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Query String' at line 1"

我该如何解决这个问题?非常感谢!

最佳答案

您尝试执行以下查询:

Query String

你需要这样做:

if ($q1 = mysqli_query($conn,"select * from joseph.inpatient_1501003f"))

而不是:

$q1 = mysqli_query($conn," select * from joseph.inpatient_1501003f");
if ($q1 = mysqli_query($conn,"Query String")){...}

关于php - mySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35271954/

相关文章:

mysql - 4 位数字用户名 - CakePHP

mysql - SUM() GROUP BY 列的结果

javascript - Angularjs - 使用数据库中的新数据重新加载范围

java - 我可以将此 Mysql 查询转换为 JPA 吗?

PHP json 编码和 JS JSON.stringify

PHP 按 id 和父 id 对数组进行排序

php - 无法使用 adodb 将字符串传递给 MySQL 存储过程

MySQL子查询仅返回顶行结果

php - 放入数据库的图像信息(名称、类型、大小、url)

php - 按元框值从数据库中获取数据(wordpress)