read
This commit is contained in:
1 parent
ee0d392ac8
commit
a7f793b22a
1 file changed
+34
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
// Check existence of id parameter before processing further
|
||||||
|
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
|
||||||
|
// Include config file
|
||||||
|
require_once "config.php";
|
||||||
|
|
||||||
|
// Prepare a select statement
|
||||||
|
$sql = "SELECT * FROM employees WHERE id = ?";
|
||||||
|
|
||||||
|
if($stmt = mysqli_prepare($link, $sql)){
|
||||||
|
// Bind variables to the prepared statement as parameters
|
||||||
|
mysqli_stmt_bind_param($stmt, "i", $param_id);
|
||||||
|
|
||||||
|
// Set parameters
|
||||||
|
$param_id = trim($_GET["id"]);
|
||||||
|
|
||||||
|
// Attempt to execute the prepared statement
|
||||||
|
if(mysqli_stmt_execute($stmt)){
|
||||||
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
|
|
||||||
|
if(mysqli_num_rows($result) == 1){
|
||||||
|
/* Fetch result row as an associative array. Since the result set
|
||||||
|
contains only one row, we don't need to use while loop */
|
||||||
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
|
|
||||||
|
// Retrieve individual field value
|
||||||
|
$name = $row["name"];
|
||||||
|
$address = $row["address"];
|
||||||
|
$salary = $row["salary"];
|
||||||
|
} else{
|
||||||
|
// URL doesn't contain valid id parameter. Redirect to error page
|
||||||
|
header("location: error.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user