joseph koh February 2016

mySQL error on syntax

   <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>

I got this error which says

"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"

How do i fix this? Appreciated much!

Answers


Thomas Rollet February 2016

You try to execute the following query :

Query String

You need to do this :

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

Instead of :

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


Anant February 2016

You are performing two queries in which first one is correct but te second one in if condition is totally wrong.

So remove if ($q1 = mysqli_query($conn,"Query String")) { condition and rest will be ok.

Note:- remove this condition and its ending } also.

Post Status

Asked in February 2016
Viewed 3,130 times
Voted 13
Answered 2 times

Search




Leave an answer