Languages :: PHP :: Whats wrong with this simple code? |
|||
| By: PHP newbee |
Date: 08/06/2003 00:00:00 |
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 | 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 | 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 | 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 | Type : Comment |
|
| VGR I use Linux & Apache. Where Can I find php.ini? |
|||
| By: sumotimor | Date: 08/06/2003 01:48:00 | 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 | Type : Comment |
|
| sumotimor how can I set "register_globals=On" ? |
|||
| By: nsanden | Date: 08/06/2003 03:06:00 | 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 | 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 | 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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








