Jump to content

Really simple code does not work


justarandomguy

Recommended Posts

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

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

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.'" />';

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.