Get data from MySQL database using id in url Topic is solved

HTML, PHP, CSS, Javascript, AJAX.............
shravaninetha
Posts: 4
Joined: Tue Jan 15, 2019 8:33 pm
Location: Hyderabad
Mood:
Age: 24
India

Get data from MySQL database using id in url

Post by shravaninetha » Sat Jan 19, 2019 1:15 pm

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'];
}
?>

User avatar
indhosting
Posts: 5
Joined: Tue Jan 15, 2019 1:23 pm
India

Re: Get data from MySQL database using id in url

Post by indhosting » Sat Jan 19, 2019 4:22 pm

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'];
}
?>
just follow that and you will get it :D :ugeek:

shravaninetha
Posts: 4
Joined: Tue Jan 15, 2019 8:33 pm
Location: Hyderabad
Mood:
Age: 24
India

Re: Get data from MySQL database using id in url

Post by shravaninetha » Sat Jan 26, 2019 12:53 pm

Thanks a lot it worked for me

riyasathe
Posts: 1
Joined: Sat Mar 23, 2019 11:56 am
India

Re: Get data from MySQL database using id in url

Post by riyasathe » Sat Mar 23, 2019 11:59 am

Thanks a lot. It was helpful for me. Excellent information in this topic. Useful!!!

Post Reply Previous topicNext topic