PHP - 基于id打开页面

I am trying to open one page base on id from web address.

My address is …/customer-single.php?id=5

And my code is:

  try {
    $connection = new PDO($dsn, $username, $password, $options);
    $CustomerID = $_GET['CustomerID'];

    $sql = "SELECT * FROM tblcustomer WHERE CustomerID = :CustomerID";
    $statement = $connection->prepare($sql);
    $statement->bindValue(':CustomerID', $CustomerID);
    $statement->execute();

    $user = $statement->fetch(PDO::FETCH_ASSOC);
  } catch(PDOException $error) {
      echo $sql . "<br>" . $error->getMessage();
  }

So I need to see only result from CustomerID=5.

Change the following line

$CustomerID = $_GET['CustomerID'];

into

$CustomerID = $_GET['id'];

Because you need to specify the name of the parameter you have used in the url.

$CustomerID = $_GET['CustomerID'];

change this into this

$CustomerID = $_GET['id'];

in here what you have done is trying to access a php GET variable using a unidentified reference. in get request you send your parameter like this ?id=5 but when you access it, you try to access it in a wrong way . So what should actually happen is in order to access that GET variable you should reference it correctly like I have shown above