gorex Posted July 8, 2007 Share Posted July 8, 2007 Hi. I got a problem with passing parameters, and hope for some help. The problem is as below: I got a website, and would like to pass a field from one page to another. So forexample, if this is how the url will look like when someone comes into the site: www.mysite.com?id=xxx Then, there is a coding on the site: $id = $_GET["id"]; and this allows me to get the id parameter and store it for use, so that on links in that page, I can just put: www.mysite.com/linkpage2.php?id=<?echo $id ?> and this will allow me to pass the id=xxx onto another page. Now the problem is this. If suppose someone came and for some reason, the id=xxx field is missing. So their url will look like www.mysite.com. Now the $id = $_GET["id"] will give an empty field, and when someone hovers over the link, it will just show www.mysite.com/linkpage2.php?id= . Is there anyway to code it so that if $id is empty, as in this case, then it will automatically fill $id=noid or something similar, so that if someone hovers over the link, it will show www.mysite.com/linkpage2.php?id=noid . I tried putting this line in: if ($id == "") {id == "noid";} but it doesn't work. When hovering over the link, it still shows www.mysite.com/linkpage2.php?id= . Any suggestion/help greatly appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 8, 2007 Share Posted July 8, 2007 You need the kind of logic you describe in the code where the links are produced, not where they are displayed. Quote Link to comment Share on other sites More sharing options...
gorex Posted July 8, 2007 Author Share Posted July 8, 2007 Unfortunately I tried putting that same logic on the target page, and it still doesn't seem to work. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 8, 2007 Share Posted July 8, 2007 perhaps we need to see some actual code where you generate some of these links ... Quote Link to comment Share on other sites More sharing options...
gorex Posted July 8, 2007 Author Share Posted July 8, 2007 Hi AndyB, thanks for the help. Below is the code I got at the moment from my index.php file. So: ///////////////////////////////////////////////////// <?php $id = $_GET["id"]; if ($id == "") {$id == "noid";} ?> <head>.......... ..... ..... <a href="list.php?id=<?echo $id?>">-Read more-</a> .... .... //////////////////////////////////////// So what till happen is when someone comes to my site, www.mysite.com?id=example , $id will be equal to example, and when people hover on the link for list.php, it will read www.mysite.com/list.php?id=example For the second line if ($id == "") {$id == "noid";}, I was hoping that when people come to my site without any ?id, ie. www.mysite.com, then the $id for the list.php link will be replaced with www.mysite.com/list.php?id=noid intead of www.mysite.com/list.php?id= . Hoever, the code doesn't work, and when people hover over the list.php link, it still shows www.mysite.com/list.php?id=. As suggested, I tried putting that code in the list.php page, so on list.php, it will have: ///////////////////////////// <?php $id = $_GET["id"]; if ($id == "") {$id == "noid";} ?> <head>.......... ... ... ///////////////////////////// Unfortunately it doesn't work as well. $id still shows up as nothing. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 8, 2007 Share Posted July 8, 2007 Try using: if ($id == "") {$id = "noid";} rather than: if ($id == "") {$id == "noid";} == is the comparison operator - so you use it to compare two values for equality = is the assignment operator - you use this to give a variable a value. Quote Link to comment Share on other sites More sharing options...
gorex Posted July 8, 2007 Author Share Posted July 8, 2007 It works! Thanks AndyB, GingerRobot. I had to put that condition code on the target page (list.php), rather than the source page (index.php), and using if ($id == "") {$id = "noid";} as GingerRobot suggested. Thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.