Jump to content

Archived

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

brown2005

If($_POST['submit'])

Recommended Posts

Hi,

On my processing pages... should i use

If($_POST['submit'])

all the time or does it not matte?

Share this post


Link to post
Share on other sites
if you are testing to see if a form as been posted you need to test as follows

if (isset($_POST['submit']))
{
// do what ever here if the form has been submited
}

Share this post


Link to post
Share on other sites
You should check any variable exists before you use it.

[code=php:0]
if (isset($_POST['submit'])) {
[/code]

Share this post


Link to post
Share on other sites
at the mo my say login_process.php script is....

$session_start();

$username = $_GET['username'];
$email = $_GET['email'];
$image= $_GET['mage'];

so to make script better should i put the

if (isset($_POST['submit'])) {

$username = $_GET['username'];
$email = $_GET['email'];
$image= $_GET['mage'];

}

Share this post


Link to post
Share on other sites
Yes. But you should also check the other before using them. The turnary operator is great in this siuation....

[code=php:0]
$username = $_GET['username'] ? $_GET['username'] : "";
$email = $_GET['email'] ? $_GET['email'] : "";
$image = $_GET['mage'] ? $_GET['mage'] : "";
[/code]

Share this post


Link to post
Share on other sites
$username = $_GET['username'] ? $_GET['username'] : "";

can you explain what this actually means please?

Share this post


Link to post
Share on other sites
[quote author=brown2005 link=topic=110381.msg446603#msg446603 date=1159964853]
$username = $_GET['username'] ? $_GET['username'] : "";

can you explain what this actually means please?
[/quote]

it's another way to write this:
[code]
<?php
// instead of this:
if (isset($_GET['username'])) $username = $_GET['username'];
else $username = '';

// just do this:
$username = isset($_GET['username']) ? $_GET['username'] : '';
?>
[/code]

read up on the ternary operator in the PHP manual for more info

Share this post


Link to post
Share on other sites
"read up on the ternary operator in the PHP manual for more info"

u got a link to this info please...

Share this post


Link to post
Share on other sites
[quote author=brown2005 link=topic=110381.msg446637#msg446637 date=1159967712]
"read up on the ternary operator in the PHP manual for more info"

u got a link to this info please...
[/quote]

really tough: http://www.php.net/ternary ;)

Share this post


Link to post
Share on other sites

×

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.