glenelkins Posted April 28, 2007 Share Posted April 28, 2007 Hi I have been modifying a script for a client. The script uses forms with post data. Now just out of interest of seeing it done in this program, how does it access the $_POST without actully having $_POST typed? For example, consider this simple form: <form name="test" action="test.php" method="post"> <input type="text" name="testtext"> </form> Now when this form is submitted to test.php, I would access the text box like $name = $_POST['testtext']; But in this program Im modifying I dont see any $_POST, it simply just has the variable like $name. Im not sure how this is done as I have never used it. Next question, When using an IF, it can get very tedious if you have only 1 comparison, for example: if ( $name == "bob" ) { echo "Bob"; } I have seen another way that omits the {} and makes the IF into one line with a colon ( : )... how does this work? Iv never actually figured that one out Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/ Share on other sites More sharing options...
heckenschutze Posted April 28, 2007 Share Posted April 28, 2007 by definition an if statement will run the first statement under it, the braces ({, }) actually group several statements into one... Also ; ends a statement, so echo "Bob"; is one statement. Therefore: if($name == "bob") echo "Bob"; is perfectly legal. As for your first question, <PHP3 loaded all $_POST, $_GET etc into globals - ie $_POST["name"] was $name (but this was later turned off)... Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240422 Share on other sites More sharing options...
glenelkins Posted April 28, 2007 Author Share Posted April 28, 2007 Hi So what is the colon i have seen in some If statements? Iv never used it Ok with the $_POST thing, but the server doesnt use PHP3 it used PHP4+ so if I was to turn it on or off where would it be done? Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240440 Share on other sites More sharing options...
AndyB Posted April 28, 2007 Share Posted April 28, 2007 So what is the colon i have seen in some If statements? Iv never used it ternary operator -> http://php.codenewbie.com/articles/php/1480/The_Ternary_Operator-Page_1.html Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240442 Share on other sites More sharing options...
glenelkins Posted April 28, 2007 Author Share Posted April 28, 2007 thanks, [quote] Ok with the $_POST thing, but the server doesnt use PHP3 it used PHP4+ so if I was to turn it on or off where would it be done? what about this? Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240445 Share on other sites More sharing options...
Barand Posted April 28, 2007 Share Posted April 28, 2007 php.ini file register_globals setting http://us2.php.net/register_globals Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240466 Share on other sites More sharing options...
glenelkins Posted April 28, 2007 Author Share Posted April 28, 2007 Well thats kind of what I thought. But the globals are on and it doesnt work! Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240475 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 Just Make a .htaccess file that contains this following texts php_flag register_globals on And place it the the same Dir. By it you can access $_POST['fld']; by using just $fld. Link to comment https://forums.phpfreaks.com/topic/49072-couple-of-questions/#findComment-240510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.