Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - open page base on id

Tags:

php

pdo

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.

like image 996
YvetteLee Avatar asked Apr 19 '26 23:04

YvetteLee


1 Answers

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.

like image 122
Yasii Avatar answered Apr 22 '26 11:04

Yasii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!