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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.php4 vs. .php

Status
Not open for further replies.

Kinl

Programmer
Mar 19, 2001
168
US
hello all,

I have installed the windows version of PHP to learn how to code php. Since I've installed it, if I have page that has the $submit variable, and I dont use .php4, it get an error saying the variable wasnt declared. But if i use .php4 I dont get the error. I'm just doing some tutorials. Heres the code that im using.

-----------------------------------------

<?

if (!$submit)
{
// if $submit doesn't exist, it implies that the form
// has not yet been submitted
// so display the first page

?>

<html>
<head>
<style type=&quot;text/css&quot;>
td {font-family: Arial;}
</style>
</head>

<body>

<font face=&quot;Arial&quot; size=&quot;+2&quot;>
The Amazing Fortune Cookie Generator
</font>

<form method=&quot;GET&quot; action=&quot;cookie.php4&quot;>
<table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot; border=&quot;0&quot;>

<tr>
<td align=&quot;center&quot;>
Pick a day
</td>
<td align=&quot;right&quot;>
<select name=&quot;day&quot;>
<option value=&quot;Monday&quot;>Monday
<option value=&quot;Tuesday&quot;>Tuesday
<option value=&quot;Wednesday&quot;>Wednesday
<option value=&quot;Thursday&quot;>Thursday
<option value=&quot;Friday&quot;>Friday
<option value=&quot;Saturday&quot;>Saturday
<option value=&quot;Sunday&quot;>Sunday
</select>
</td>
</tr>

<tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Hit me!&quot;>
</td>
</tr>
</table>
</form>
</body>

</html>


<?
}
else
{

// if $submit does exist, the form has been submitted
// so process it with switch()

// the decision variable here is the day chosen by the user
switch ($day)
{

// first case
case &quot;Monday&quot;:
$fortune = &quot;Never make anything simple and efficient when a way can be
found to make it complex and wonderful.&quot;;
break;

// second case
case &quot;Tuesday&quot;:
$fortune = &quot;Life is a game of bridge -- and you've just been
finessed.&quot;;
break;

case &quot;Wednesday&quot;:
$fortune = &quot;What sane person could live in this world and not be
crazy?&quot;;
break;

case &quot;Thursday&quot;:
$fortune = &quot;Don't get mad, get interest.&quot;;
break;

case &quot;Friday&quot;:
$fortune = &quot;Just go with the flow control, roll with the crunches,
and, when you get a prompt, type like hell.&quot;;
break;

// if none of them match...
default:
$fortune = &quot;Sorry, closed on the weekend&quot;;
break;

}

?>

<html>
<head>
<basefont face=&quot;Arial&quot;>
</head>

<body>
Here is your fortune for <? echo $day; ?>:
<br>
<b><? echo $fortune; ?></b>

</body>
</html>

<?
}
?>


-------------------------------------

Is there anything wrong w/ this code? Its a tutorial on Developer Shed for PHP

Thank you ,

shorty
 
That's not a problem.

That's right code and he says there's an error. It's cause you have PHP4.1.x and by default it sends you a warning everytime you use a var that is not declared.

To get more safety, you should replace the if line by:

if ($_GET['submit'])

This way you don't get this error any more.

Another thing you can do, is changing in the PHP.INI the values of the error_reporting.

error_reporting = E_ERROR & ~E_NOTICE

This way it shows all the errors and not those stupid warnings of the vars not declared. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top