Get data from MySQL database using id in url Topic is solved
-
- Posts: 4
- Joined: Tue Jan 15, 2019 8:33 pm
- Location: Hyderabad
- Mood:
- Age: 29
Get data from MySQL database using id in url
I'm trying to pull data from MySQL database using ID in the URL like site/order.php?id=24
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$servername = "localhost";
$username = "xxxx";
$password = "xxxxxx";
$db_name = "xxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT * FROM `orders` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><br>";
echo $row['id'];
echo $row['order_id'];
echo $row['type'];
echo $row['price'];
}
?>
-
- Posts: 8
- Joined: Tue Jan 15, 2019 1:23 pm
- Has thanked: 2 times
- Been thanked: 7 times
Re: Get data from MySQL database using id in url
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$servername = "localhost";
$username = "xxxx";
$password = "xxxxxx";
$db_name = "xxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `orders` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><br>";
echo $row['id'];
echo $row['order_id'];
echo $row['type'];
echo $row['price'];
}
?>


-
- Posts: 4
- Joined: Tue Jan 15, 2019 8:33 pm
- Location: Hyderabad
- Mood:
- Age: 29
Re: Get data from MySQL database using id in url
Thanks a lot. It was helpful for me. Excellent information in this topic. Useful!!!