visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Whats wrong with this simple code?


By: PHP newbee U.S.A.  Date: 08/06/2003 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
This is test2.php:

<html>
<head>
<title>Saints</title>
</head>
<body bgcolor="#ffffff">

<?

if(empty($name))
{
?>
<form method="GET" action="test2.php">
Name:
<input type="text" name="name" size=30>


<input type="submit">
</form>
<?
}
else{
echo "inside else...";
}
?>
</body>
</html>

When I write something in the text area and press the submit button,
I never see the message "inside else..."

Why the $name is empty?

By: lexxwern Date: 08/06/2003 01:29:00 English  Type : Comment
Try THis:
<?

if(empty($_GET['name']))
{
echo '
<form method="GET" action="test2.php">
Name:
<input type="text" name="name" size=30>


<input type="submit">
</form> ';
}
else{
echo "inside else...";
}
?>
By: PHP newbee Date: 08/06/2003 01:41:00 English  Type : Comment
thanx lexxwern it works,

but how can I set the $name?

Also does your code works with POST method?
By: VGR Date: 08/06/2003 01:44:00 English  Type : Answer
alternatively, stick with your normal code and set "register_globals=On" in your php.ini file...
By: PHP newbee Date: 08/06/2003 01:46:00 English  Type : Comment
VGR
I use Linux & Apache. Where Can I find php.ini?
By: sumotimor Date: 08/06/2003 01:48:00 English  Type : Comment
It's definitely a register_globals issue.
try this:
if(empty($_REQUEST['name']))

which will work whether register_globals is on or off. Good habit.
By: PHP newbee Date: 08/06/2003 02:28:00 English  Type : Comment
sumotimor

how can I set "register_globals=On" ?
By: nsanden Date: 08/06/2003 03:06:00 English  Type : Comment
If you can't edit your PHP.ini file (maybe your on a shared host) you can try making a .htaccess file, and adding this one line to it...
php_value register_globals 1

This may or may not work depending on how your host has setup the httpd.conf file.
By: blehda Date: 08/06/2003 17:03:00 English  Type : Comment
how about a form method="POST" because i guess you want to POST the name and dont want to get it dont you ?? :-)
By: sumotimor Date: 08/06/2003 17:49:00 English  Type : Comment
My point is, you don't need (and should rely on) register_globals. By referencing any POST or GET variables as elements in the $_POST, $_GET, or $_REQUEST super-arrays, you get much better security for your scripts. It's a little bit more typing, but users can no longer spoof variables in your page by supplying their own values in the url, e.g. typing <A HREF="http://example.com/test2.php?isadmin=true">http://example.com/test2.php?isadmin=true</a> to attempt to fake admin access.

<html>
<head>
<title>Saints</title>
</head>
<body bgcolor="#ffffff">

<?

if(empty($_POST['name']))
{
?>
<form method="GET" action="test2.php" method="post">
Name:
<input type="text" name="name" size=30>


<input type="submit">
</form>
<?
}
else{
echo "inside else...";
}
?>
</body>
</html>
By: lexxwern Date: 08/06/2003 17:52:00 English  Type : Comment
>> but how can I set the $name?
its advisable to stick with $_GET['name'] instead of $name..

Do register to be able to answer

EContact
browser fav
page generated in 319.148780 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page