-1

I keep getting this error

Connection failed: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''book' where 'ISBN' = 1' at line 1

I've tried everything but I don't understand why it's not working

$sql = "select 'BookTitle' from 'book' where 'ISBN' = $ISBN";
$result = $conn->query($sql);
$booktitle = $result;

if ($conn->error) {
    die("Connection failed: " . $conn->error);
}]    
Dave
  • 3,046
  • 7
  • 19
  • 32
Mark McE
  • 1
  • 3

3 Answers3

1

you don't need quotes around columns you want to select or table name. Also don't forget that your code is vulnerable to sql injection. You can use prepare method to avoid this.

$sql = "select BookTitle from book where 'ISBN' = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $ISBN);
$stmt->execute();
$stmt->bind_result($result);
RomMer
  • 131
  • 12
0
$sql = "select BookTitle from book where ISBN = $ISBN";

You don't need single quotes everywhere. Columns and Table name are not php strings. Also be aware that your code is open to SQL injection so make sure you refactor it to use prepared statements.

pr1nc3
  • 7,400
  • 3
  • 21
  • 35
-1
$sql = "select BookTitle from book where ISBN = '$ISBN'";

For sure, asumming that your column is BookTitle and your table is book

akroma
  • 45
  • 1
  • 1
  • 6