Er Deepesh Tripathi
Er Deepesh Tripathi

Reputation: 29

how to pass id in url

I am trying to send id in url and getting the url like this:

edittruck.php?truck_id=%2715%27

I need like this :

edittruck.php?truck_id=15   Any idea please 

After that I want to get the truck_id in edittruck.php page for update.

Upvotes: 1

Views: 5942

Answers (6)

Er Deepesh Tripathi
Er Deepesh Tripathi

Reputation: 29

Thank you so much all .. I have no need to replace now ... I got the error on same moment and fixed that

<a href="edittruck.php?truck_id=<?php echo$row["truck_id"];?>">Edit</a>

Upvotes: 0

Abhishek
Abhishek

Reputation: 603

yes, you are using single quotes.

i.e. edittruck.php?truck_id='27'

you can use this,

$truck_id = str_replace('%20',' ',$truck_id);

now you can pass $truck_id in single quotes also.

For getting $truck_id in your 'edittruck.php' file use,

if(isset($_GET['truck_id']))
{
    $truck_id = $_GET['truck_id'];
}
?>

or use $_REQUEST instead of $_GET.

Upvotes: 2

Manjeet Barnala
Manjeet Barnala

Reputation: 2995

Use this code :

$truck_id = 15; ///your truck id here
<a href="edittruck.php?truck_id=<?php echo $truck_id; ?>" >Edit</a>

And in edittruck.php

<?php 
$truck_id='';
if(isset($_GET['truck_id']))
{
    $truck_id = $_GET['truck_id'];
}
?>

Upvotes: 0

Hanan Ashraf
Hanan Ashraf

Reputation: 518

Try this.

<a href="edittruck.php?truck_id='.$truck_id.'">Edit</a>

Upvotes: 0

Ankur Tiwari
Ankur Tiwari

Reputation: 2782

I believe your are passing variable in your URL like

truck_id='15'

remove single quotes from the URL and you will get

truck_id=15

Upvotes: 0

Pupil
Pupil

Reputation: 23948

You are adding single quotes around query parameters.

Single quote is encoded as %27.

Remove single quotes before and after 27

Upvotes: 0

Related Questions