Jump to content

Couple Of Questions


glenelkins

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.