adrian_ Posted September 28, 2011 Share Posted September 28, 2011 Hi, I'm trying to pass a variable into a URL and apparently I'm doing it wrong this code is OK $id = $3; echo '<a href="newPage.php?id=3"></a> If I use $id = $_GET['id']; echo $id; on the newPage.php, I echo 3 whereas, if I do $id = $3; echo '<a href="newPage.php?id="'.$id.'"></a> when echo out on the newPage.php it prints out nothing also, in current url look like this: www.site.com/newPage.php?id= What am I doing wrong? Many thanks Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/ Share on other sites More sharing options...
objnoob Posted September 28, 2011 Share Posted September 28, 2011 $id = $3; $3 is not a valid variable name, nor is it a valid literal. Try $id=3; Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/#findComment-1273765 Share on other sites More sharing options...
adrian_ Posted September 28, 2011 Author Share Posted September 28, 2011 My bad for $3 I tried the way you suggested, but still no luck. Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/#findComment-1273769 Share on other sites More sharing options...
objnoob Posted September 29, 2011 Share Posted September 29, 2011 echo '<a href="newPage.php?id="'.$id.'"></a> That is wrong too! Try (how I would do) echo "<a href='newPage.php?id={$id}'></a>"; or (how you were trying, but fixed...) echo '<a href="newPage.php?id='.$id.'"></a>'; Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/#findComment-1273775 Share on other sites More sharing options...
xyph Posted September 29, 2011 Share Posted September 29, 2011 <?php $id = 3; echo '<a href="page.php?id='.$id.'">link</a>'; ?> works fine for me. Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/#findComment-1273800 Share on other sites More sharing options...
adrian_ Posted September 29, 2011 Author Share Posted September 29, 2011 Hi guys Apparently that was my problem, I had a double quote immediately after the equal sign. Got rid of it, everything works Thank you Link to comment https://forums.phpfreaks.com/topic/248069-passing-variables-into-url/#findComment-1273863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.