Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Function Problem

Status
Not open for further replies.

job357

Technical User
Sep 16, 2002
106
US
Greetings,
I have installed PHP on Solaris 10 and now have problems following a tutorial, or at least my results aren't what the tutorial displays, the code is:

movie1.php:
<HTML>
<HEAD>
<TITLE>Find my Favorite Movie!</TITLE>
</HEAD>
<BODY>
<?php
echo "<a href=' echo "Click here to see information about my favorite movie!";
echo "</a>";
?>
</BODY>
</HTML>

moviesite.php:
<HTML>
<HEAD>
<TITLE>My Movie Site - <?php echo $favmovie ?></TITLE>
</HEAD>
<BODY>
<?php

echo "My favorite movie is ";
echo $favmovie;
echo "<br>";
$movierate=5;
echo "My movie rating for this movie is: ";
echo $movierate;
?>
</BODY>
</HTML>

My results are:
My favorite movie is <-- missing value
My movie rating for this movie is: 5
 
This is the register_globals on vs. off problem. If the tutorial was written more than about a year or two ago, it assumed register_globals was ON by default. This was determined to be a security problem and PHP is now installed with this value set to OFF.

Use the superglobal $_GET to reference values passed via the URL and $_POST for values passed via forms with the method of POST.

In your case:
Code:
    echo "My favorite movie is ";
    echo $_GET['favmovie'];

Ken
 
Thanks, this information has been very helpful!
 
Ken,
I am really new with PHP, that being said, why did I drop the '$' for the variable $favmovie and call it,
"echo $_GET['favmovie'];" instead of like: echo $_GET['$favmovie'];

Thanks.
 
Because "favmovie" is a literal string, not a variable. You could do something like:

$foo = 'favmovie';
print $_GET[$foo];

in which case I've stored the string literal 'favmovie' in the variable $foo then used that variable to reference the array element.


You need to be aware of how PHP interprets doublequotes and singlequotes differently from each other. See the PHP online manual section on Strings[/links]


Want the best answers? [url=http://www.catb.org/~esr/faqs/smart-questions.html]Ask the best questions!


TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top