PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE customers(customerId INT); INSERT INTO customers VALUES(1);
Copy Clear
Copy Format Clear
<?php // Check existence of id parameter before processing further if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){ // Include config file //require_once "../includes/config.php"; // Prepare a select statement // This query works, loads the page, but i want to adjust it to orders $sql = "SELECT * FROM customers WHERE customerId = ?"; if($stmt = mysqli_prepare($con, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "i", $param_id); // Set parameters $param_id = 1 ; //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 // $addValue = $row['#']; } else{ // URL doesn't contain valid id parameter. Redirect to error page header("location: src/error.php"); exit(); } } else{ echo "Oops! Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); // Close connection mysqli_close($con); } else{ // URL doesn't contain id parameter. Redirect to error page header("location: src/error.php"); exit(); } ?>
Show:  
Copy Clear