Reputation: 3
I am trying to pass and retrieve a variable from one page to another. When i run the page i'm getting the error 'URL not found'. So im guessing my variable hasn't been passed to the page.
When i click on the pages edit.php and delete.php the corresponding url is being displayed. i.e edit.php?id=1, edit.php?id=2 etc. I have tried a number of different things but can't seem to resolve this issue.
Here is the source code:
First Page (The links):
$ads_id = $row ["ads_id"]; //Value retrieved from database and stored in local variable
<a href="delete.php?id=' . $ads_id . '">
<a href="edit.php?id=' . $ads_id . '">
edit.php
if (isset($_GET['id'])) {
$ads_id = $_GET['id'];
}
else
{
echo "URL not found";
}
Upvotes: 0
Views: 845
Reputation: 392
I think the problem with your code is that it doesn't have the php opening and closing tag
it should look like
<?php
$ads_id = $row["ads_id"]; //Value retrieved from database and stored in local variable
?>
<a href="delete.php?id=<?php echo $ads_id; ?>">
<a href="edit.php?id=<?php echo $ads_id; ?>">
Upvotes: 0
Reputation: 95103
You can try this ... you are having errors because of the single quote '
issue ... and since you would be adding multiple links this php function
might help you ...
$ads_id = $row ["ads_id"]; //Value form database source
echo addLink("delete.php?id={$ads_id}","Link1") , "<br />";
echo addLink("edit.php?id={$ads_id}","Link1") , "<br />";
function addLink($url,$name)
{
return sprintf("<a href=\"%s\">%s</a>",$url,$name);
}
Upvotes: 0
Reputation: 27227
$ads_id = $row ["ads_id"]; //Value retrieved from database and stored in local variable
<a href="delete.php?id=' . $ads_id . '">
<a href="edit.php?id=' . $ads_id . '">
Should look like this:
<?php
$ads_id = $row["ads_id"]; //Value retrieved from database and stored in local variable
?>
<a href="delete.php?id=<?=$ads_id?>">
<a href="edit.php?id=<?=$ads_id?>">
Upvotes: 1