newb needs help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

newb needs help

Post by defx »

:oops:

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 :)
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

you have to assign the variable to something
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post by defx »

But what exactly would I assign it too ?
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

Can we see the whole script? Also $Firstname means nothing if you dont have a $firstname = "Aaron";
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post 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"
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post 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.
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post 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>
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

process.php

Post by Vicious »

process.php

Code: Select all

$variablename=$_GET&#1111;'variable'];
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post 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.
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post by defx »

Ah, thank you a lot, it works! :)
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

np
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post 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&#1111;'sect']; 

	$red = "#B20E0F";
	$green = "#0FB12";
	$blue = "#0F5BB1";
	$white = "#FFFFFF";
	$gray = "#CDCDCD";
	
if ($sect) &#123;
print('<body bgcolor=$sect>');
&#125;

else &#123;
print("error!");
&#125;
?>
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

is the form its getting it from named the same as the variable?
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

Post by defx »

its not a form, theres a link on another page thats linked to ?sect=red and another thats linked to ?sect=blue
Post Reply