首页 > 解决方案 > PHP - open page base on 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.

标签: phppdo

解决方案


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.


推荐阅读