user3772864
user3772864

Reputation: 63

how to get id from URL using php

I have this code on my Search page:

<a href="detail.php?id=<?php echo $ido;?>"STYLE="TEXT-DECORATION: NONE"><?php echo $nume;?></a>

and i also have a detail.php page. I need to get the $ido value from the URL so that I can use it in the detail.php page to retrieve information from the database.

The detail page has a URL like this: detail.php?id=17 , I need to get the value after the =, in this case 17, into a variable.

Upvotes: 2

Views: 145948

Answers (3)

Palak Varu
Palak Varu

Reputation: 1

If still having problem then try:

  • To fetch integer value:

    $id = intval($_GET['id']);
    
  • To fetch string value:

    $name = strval($_GET['name']);
    

Upvotes: 0

Donn Frederick Lucas
Donn Frederick Lucas

Reputation: 40

You can also use $_SERVER['QUERY_STRING'];

But this will only fetch id=17

Upvotes: 0

Kinnectus
Kinnectus

Reputation: 899

In your detail.php use: $id = $_GET['id']; you can then use $id around the rest of your page.

Upvotes: 14

Related Questions