justarandomguy Posted March 8, 2011 Share Posted March 8, 2011 Hello; I'm new to php and to programming in general, but i want to do a little app to help a process on my work, you know, just being pro-active (hoping it doesnt come and byte me in the a** in the future, you know.. "you did it now our life depend on it and you fix it right now!!). So.. I have this really simple piece of code, but its not working and i cant figure out why. I'm trying to use echo to print a couple of link but when i put in the second line everything messes up. the code is: (note the "test lines" i just added them to try to understand what is doing) <?php $client = $_GET['client']; echo "Client " . $client . "<br />"; echo "test line 1"; echo "<a href=\"link1.php?client=".$client.">Link 1</a><br>"; echo "test line 2"; echo "test line 3"; echo "<a href=\"link2.php?client=".$client.">Link 2</a><br>"; ?> When i open the page on firefox i get: === Client myclient test line 1Link 2 === Where the link (underlined) text is "Link 2" but the it points to something totally different (a mix of the rest of the code). If I remove the second link, like here: <?php $client = $_GET['client']; echo "Client " . $client . "<br />"; echo "test line 1"; echo "<a href=\"link1.php?client=".$client.">Link 1</a><br>"; echo "test line 2"; echo "test line 3"; ?> I get what i'd expect: === Client myclient test line 1Link 1 test line 2test line 3 === Im totally lost, im not sure if its a browser issue, a server issue or just the code My setup: WAMP 2.1 (Apache) I'm opening the "site" with Firefox 3.6.15 and IE6, both show the same result Windows XP (dont know if it matters) The file is saved as php tried changing "echo" with "print", same result Umm.. thats it... Please let me know if you need any more info Thanks everyone edit: typo on subject edit: yet another typo Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/ Share on other sites More sharing options...
kenrbnsn Posted March 8, 2011 Share Posted March 8, 2011 You never close the quoted string for the first href attribute, use this code instead: <?php $client = (isset($_GET['client'])?$_GET['client']:'NoClient'; // test to see if $_GET['client'] is set before using it echo "Client " . $client . "<br />"; echo 'test line 1<br />'; echo "<a href='newserver.php?client=$client'>Link 1</a><br />"; echo 'test line 2<br />'; echo 'test line 3<br />'; echo "<a href='decomm.php?client=$client'>Link 2</a><br />"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184579 Share on other sites More sharing options...
Mahngiel Posted March 8, 2011 Share Posted March 8, 2011 You never close the quoted string for the first href attribute, use this code instead: Beat me to it. BTW, when I use php and echo to form pages, i only use a single apostrophe, so that I can clearly see quotations for values. ie: echo '<input type="text" name="'.$var.'" />'; Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184586 Share on other sites More sharing options...
justarandomguy Posted March 8, 2011 Author Share Posted March 8, 2011 holy.... that was fast! Thank you very much, it is working now! I didnt know i could use ' instead of " on the html part, i dont have to \" or concatenate with . now. Again, thanks a lot! Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184588 Share on other sites More sharing options...
justarandomguy Posted March 8, 2011 Author Share Posted March 8, 2011 Gotcha Mahngiel Ill remember that tip Thanks! Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184590 Share on other sites More sharing options...
justarandomguy Posted March 8, 2011 Author Share Posted March 8, 2011 so... kenrbnsn I tried using the little part that you added at the beginning of your reply, i didn't have that and i guess its a good idea: $client = (isset($_GET['client'])?$_GET['client']:'NoClient'; but im getting: Parse error: syntax error, unexpected ';' in C:\wamp\www\data.php on line 10 if i remove the ; of course i get another error. I feel kind of ashamed of myself for asking but i dont really know how is that working so i cant fix it myself... do you know whats missing? Thanks again Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184604 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2011 Share Posted March 8, 2011 My mistake -- I left out a closing ")" -- I do that all the time in my own code... <?php $client = (isset($_GET['client']))?$_GET['client']:'NoClient'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184607 Share on other sites More sharing options...
justarandomguy Posted March 8, 2011 Author Share Posted March 8, 2011 That did the trick. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/230000-really-simple-code-does-not-work/#findComment-1184614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.