...

View Full Version : how to write it properly?



anna90
05-23-2009, 08:24 PM
Can you tell me how to write it properly ?

if(isset($_POST['button'])) && ($_POST['form'] = !null)){
echo 'choose something';
}
else{
echo 'great choice!';
}

timgolding
05-23-2009, 08:30 PM
if(isset($_POST['button'])) && ($_POST['form'] != null)){
echo 'choose something';
}
else{
echo 'great choice!';
}


or



if(!empty(@$_POST['form'])){
echo 'choose something';
}
else{
echo 'great choice!';
}


The @ turns off error reporting for getting the function/variable after so avoids the need to use isset.

anna90
05-23-2009, 08:36 PM
if(isset($_POST['button'])) && ($_POST['form'] != null)){
echo 'choose something';
}
else{
echo 'great choice!';
}


or



if(!empty(@$_POST['form'])){
echo 'choose something';
}
else{
echo 'great choice!';
}


The @ turns off error reporting for getting the function/variable after so avoids the need to use isset.
first one

Parse error: syntax error, unexpected T_BOOLEAN_AND

second one

Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '$'

timgolding
05-23-2009, 08:46 PM
Sorry i didn't test them let me fix that.

timgolding
05-23-2009, 08:52 PM
Sorry empty seems to check if it exsists and is empty all in one hit.



<?php
if(empty($_POST['form'])){
echo 'choose something';
}
else{
echo 'great choice!';
}
?>


However you might want to use



<?php

if(!isset($_POST['button']) && $_POST['form'] == ""){
echo 'choose something';
}
else{
echo 'great choice!';
}
?>


As empty returns true if $_POST["form"] is set to 0 for instance

anna90
05-23-2009, 08:59 PM
thank you!
a hug to you :rolleyes:

timgolding
05-23-2009, 09:06 PM
thank you!
a hug to you :rolleyes:
:D thanks

venegal
05-24-2009, 03:40 AM
If by how to write it properly you meant why doesn't my code work it's because you forgot a left paren right after the if.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum