Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-23-2009, 07:24 PM   PM User | #1
anna90
New to the CF scene

 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
anna90 is an unknown quantity at this point
how to write it properly?

Can you tell me how to write it properly ?
Code:
if(isset($_POST['button'])) && ($_POST['form'] = !null)){
echo 'choose something';
}
else{
echo 'great choice!';
}
anna90 is offline   Reply With Quote
Old 05-23-2009, 07:30 PM   PM User | #2
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
PHP Code:
if(isset($_POST['button'])) && ($_POST['form'] != null)){
echo 
'choose something';
}
else{
echo 
'great choice!';

or

PHP Code:
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.
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 05-23-2009, 07:36 PM   PM User | #3
anna90
New to the CF scene

 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
anna90 is an unknown quantity at this point
Quote:
Originally Posted by timgolding View Post
PHP Code:
if(isset($_POST['button'])) && ($_POST['form'] != null)){
echo 
'choose something';
}
else{
echo 
'great choice!';

or

PHP Code:
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
Quote:
Parse error: syntax error, unexpected T_BOOLEAN_AND
second one
Quote:
Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '$'
anna90 is offline   Reply With Quote
Old 05-23-2009, 07:46 PM   PM User | #4
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Sorry i didn't test them let me fix that.
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 05-23-2009, 07:52 PM   PM User | #5
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Sorry empty seems to check if it exsists and is empty all in one hit.

PHP Code:
<?php
if(empty($_POST['form'])){
echo 
'choose something';
}
else{
echo 
'great choice!';
}
?>
However you might want to use

PHP Code:
<?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
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 05-23-2009, 07:59 PM   PM User | #6
anna90
New to the CF scene

 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
anna90 is an unknown quantity at this point
thank you!
a hug to you
anna90 is offline   Reply With Quote
Old 05-23-2009, 08:06 PM   PM User | #7
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Quote:
Originally Posted by anna90 View Post
thank you!
a hug to you
thanks
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 05-24-2009, 02:40 AM   PM User | #8
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
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.
venegal is offline   Reply With Quote
Reply

Bookmarks

Tags
button, form, isset, post

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:59 AM.


Advertisement
Log in to turn off these ads.