1

I'm new to PHP. I try to build simple page with PHP and MySql, but failed to display the spesific data.

I try this: Get data from MySQL database by specific id in url to display data by "id_pemesanan" not "id" from the database.

But it's failed.

This is my code:

<?php
$id = $_GET['id_pemesanan'];
$mysqli = new mysqli("localhost", "root", "", "mad");
$query = "SELECT * FROM pesanan WHERE id_pemesanan ='". $id."'";
$result = $mysqli->query($query);
$row = $result->fetch_array(MYSQLI_BOTH);
{
echo "<p>$row[asal]</p>";
    }
?>

This is my database table structure:

CREATE TABLE `pesanan` (
  `id` int(11) NOT NULL,
  `id_pemesanan` int(11) NOT NULL,
  `pemesan` text NOT NULL,
  `asal` text NOT NULL,
  `lat` varchar(500) NOT NULL,
  `lng` varchar(500) NOT NULL,
  `tujuan` text NOT NULL,
  `lat_tujuan` varchar(500) NOT NULL,
  `long_tujuan` varchar(500) NOT NULL,
  `jarak` text NOT NULL
) ENGINE=MyISAM

I want display the spesific data using url like: http://localhost/mios/open/lengkap.php?=11772

The "11772" in the url is from "id_pemesanan"

I want the code to display the data. But, the error messages come.

Here the error massage:

Notice: Undefined index: id_pemesanan in 
C:\xampp\htdocs\mios\open\lengkap.php on line 2
Ahmad Z
  • 27
  • 6

4 Answers4

2

Your url must be like following..

http://localhost/mios/open/lengkap.php?id_pemesanan=11772
Rakesh P
  • 438
  • 5
  • 19
0

You are missing to pass your get parameter on url

http://localhost/mios/open/lengkap.php?id_pemesanan=11772
MD. Jubair Mizan
  • 1,539
  • 1
  • 12
  • 20
0

Problem is your request URL is missing parameter id_pemesanan, should like this:

http://localhost/mios/open/lengkap.php?id_pemesanan=11772

See Query string - Wikipedia

Typical URL containing a query string is as follows:

http://example.com/over/there?name=ferret

When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, name=ferret unchanged, to the program. The question mark is used as a separator, and is not part of the query string.

Community
  • 1
  • 1
Calos
  • 1,783
  • 19
  • 28
0

You should be add query parameter in url, because that error is about index to GET not found query parameter with index id_pemesanan.

http://localhost/mios/open/lengkap.php?id_pemesanan=11772