I am using wampserver for php and mysql database. in my php file, after executing some code to insert in mysql database, I want to redirect browser to another html page that has php code in it. This page needs value of the variable id to fetch data from my sql database. So I send value of id by below code in the end of php code.
header('Location: lostItem.php?id=$id');
The recieving file has below code to get value of id.
$id= $_GET['id'];
But, it turns out that there is no value of id passed i.e. the receiving file shows url :
http://localhost/Lost%20and%20Found/lostItem.php?id=$id
instead of showing
http://localhost/Lost%20and%20Found/lostItem.php?id=11
I already have another page that sends same data (value of id) to receiving file. It has below code in it for that.
echo "<a class='listOfItems' href='lostItem.php?id=$id'>";
echo $item;
echo "</a>";
And that works fine. But when I try to do same thing by using header, it doesn't work. Before using header, I have made sure that variable $id has right integer value. But it doesn't send that value by using header.
Is it that data can't be sent by this method using header? If so, please suggest an alternative method.