数据库查询无法按预期运行

问题描述:

Hi i'm using a query to extract data from the table, from a dynamic link. and ummm the code I've used SEEMS to be okay, yet i get a 'Database Query Failed' can someone tell me why?

here's the code:

<?php
$PIN = $_GET['Pin'];

$query="SELECT * FROM Accident_Investigation WHERE PIN = $PIN";
$result = mysqli_query($connection, $query);

if(!$result){
    die("Database query failed.");
    } 
?>

Change $PIN to '$PIN' in SQL statement provided everything else works fine.

$PIN = (!isset($_GET['Pin']) ? $_GET['Pin'] : null);
$query = "SELECT * FROM Accident_Investigation WHERE PIN = '" . $PIN . "'";
$result = mysqli_query($connection, $query);
if (!$result){
  mysqli_error($connection);
  die("Database query failed.");
}