Page 1 of 2
newb needs help
Posted: Mon Feb 16, 2004 11:50 pm
by defx
Ok, I am beginning to learn PHP after taking a few VB classes and messing around with PHP. One thing I am majorly having a problem is variables. I was trying one of the first things in PHP, and thats defining a variable in a URL (ie- ?p=about) anyway, I coded everything that was put into the book:
<?php
/* This page my have numerous lines of code containing the following print statement */
print "<H2> <CENTER> <B> Hello, $FirstName. </b> </CENTER> </H2> <BR>\n";
/* This page may have more code after the print statement we are focusing on. */
?>
anyway, when i go to the url: file.php?FirstName=Aaron I get the following message: Notice: Undefined variable: FirstName in file.php on line 2
Hello .
I have an apache server installed onto my computer that allows me to use PHP without a webhost, some of my other scripts are working, but why isn't this one?
Also, could someone please explain when to use " compared to ' ?
Thanks, Help would be gratefully appreciated

Posted: Mon Feb 16, 2004 11:57 pm
by Vicious
you have to assign the variable to something
Posted: Tue Feb 17, 2004 12:00 am
by defx
But what exactly would I assign it too ?
Posted: Tue Feb 17, 2004 12:02 am
by Vicious
Can we see the whole script? Also $Firstname means nothing if you dont have a $firstname = "Aaron";
Posted: Tue Feb 17, 2004 12:06 am
by defx
well i've tried it to ways, defining it into the URL (?FirstName=Aaron [which I don't get, shouldn't I be able to do that?]) also using a form with a textbox with the name of "FirstName"
Posted: Tue Feb 17, 2004 12:07 am
by defx
And I don't want to put into the code that $firstname = "Aaron"; because I want to be able to type into the URL: ?FirstName=Jason and it end up say Hello, Jason.
Posted: Tue Feb 17, 2004 12:09 am
by Vicious
Code: Select all
<input type="text" name="thebox" value="Your Name">
<textarea name="message">
Please write your message here.
</textarea>
<input type="submit" value="Submit">
<form action="process.php" method="post">
Form elements and formatting etc.
</form>
process.php
Posted: Tue Feb 17, 2004 12:10 am
by Vicious
process.php
Code: Select all
$variablename=$_GETї'variable'];
Posted: Tue Feb 17, 2004 12:11 am
by Vicious
Posted: Tue Feb 17, 2004 12:11 am
by defx
Yeah I tried that, it didn't work. Here's the thing, I have a PHP book the Visual Quickstart Guide by Larry Ullman, and he has the same code I do, and he said it worked.
Posted: Tue Feb 17, 2004 12:13 am
by defx
Ah, thank you a lot, it works!

Posted: Tue Feb 17, 2004 12:16 am
by Vicious
np
Posted: Tue Feb 17, 2004 12:16 am
by defx
Thanks again. I have just one more question about a script though. The whole reason I was asking for that is because I am making a simple background script, where the user clicks a color and the background changes to that color, sort of like it switches themes. So why does this not work now ?
I want the users to click on a red link, and the bg be the red color defined below. Right now all that shows up is the ugly lime green
Code: Select all
<?
$sect=$_GETї'sect'];
$red = "#B20E0F";
$green = "#0FB12";
$blue = "#0F5BB1";
$white = "#FFFFFF";
$gray = "#CDCDCD";
if ($sect) {
print('<body bgcolor=$sect>');
}
else {
print("error!");
}
?>
Posted: Tue Feb 17, 2004 12:19 am
by Vicious
is the form its getting it from named the same as the variable?
Posted: Tue Feb 17, 2004 12:22 am
by defx
its not a form, theres a link on another page thats linked to ?sect=red and another thats linked to ?sect=blue