Page 1 of 1

[SOLVED] Slight Problem Undefined Variable

Posted: Mon Apr 19, 2004 8:17 am
by Themodem
Hi all
im just messing around with php and have hit a problem

ive got some simple code

Code: Select all

<?php echo("$name"); ?>
and i keep getting Notice: Undefined variable: name error.

Can anyone help me?

i am using EasyPHP

Cheers Lee

Posted: Mon Apr 19, 2004 8:19 am
by JayBird
you need to do something like this

Code: Select all

$name = "Mark"; // Define the variable

echo $name; // Use the variable
Mark

Posted: Mon Apr 19, 2004 8:28 am
by Themodem
i should have put the reason for the code

i am using it so i can use a link like

index.php?name=Lee

The error is fixed but the name still doesnt appear

Cheers Lee

Posted: Mon Apr 19, 2004 8:30 am
by JayBird
ah, if you are passing the name through the query string, you will need to do this

Code: Select all

$name = $_GET['name'];// Define the variable 

echo $name; // Use the variable

Posted: Mon Apr 19, 2004 8:53 am
by Themodem
Works like a charm thanks :D