php - 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.
解决方案
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.
推荐阅读
- python - Python Zeep Client 使用 Ontario Health EBS MCEDT WSDL(SOAP) webservice
- typescript - 类型 { } 中始终缺少属性
- c++ - 在 C++ 中转换为二进制文件是否包含显示其中有内容的文本?
- java - 覆盖方法 onCreateView 导致错误
- c# - 类型相同但需要显式转换?
- java - 使用 java 正则表达式解析 apache 日志文件
- node.js - StencilJS 的节点 Pollyfill
- css - 如何处理需要其他 SCSS npm 模块的 NPM 包的 SCSS 导入?
- windows - IF 块和变量 - 最终的 ELSE 始终运行,而不是第一部分
- amazon-web-services - 使用专用链接连接到本地主机