Jump to content

if statement is true but elseif statment is echoed - Any help?


Recommended Posts

I can't spot the mistake here - as usual Im sure its just syntax. I just started to learn PHP yesterday.

 

 

Heres the code:

http://pastie.caboo.se/127816

 

 

 

I'm following a tutorial and in this particular video it is hard to see the difference between () {} [] etc.

 

Should it be:

$data2		= 	$_POST['data2'];
$data3		= 	$_POST['data3'];
$data4		= 	$_POST['data4'];
$submit		= 	$_POST['submit']

 

or

 

$data2		= 	$_POST{'data2'};
$data3		= 	$_POST{'data3'};
$data4		= 	$_POST{'data4'};
$submit		= 	$_POST{'submit'}

 

Other than that can anyone spot a mistake?

 

Any help would be appreciated.

 

;)

Maybe I'm not looking hard enough...but there's a couple of things to consider:

 

1) Where are your form inputs for data2, data3 and data4?

 

2) What kind of data are you expecting with data2, data3 and data4?

 

In your IF statements, if you are just trying to see whether data2, data3, and data4 exist, use the isset() function.  IF statements can be read a couple of ways...the number 1 will return TRUE and the boolean data TRUE will obviously return TRUE...so when you say...

 

if ($submit && $data2 && $data3 && $data4)

 

you are really saying "If all of these variables equate to TRUE (whether it be boolean TRUE or string/number 1) then blah blah blah"

1) Where are your form inputs for data2, data3 and data4?

 

2) What kind of data are you expecting with data2, data3 and data4?

 

 

What I have is basically a webpage where users can input information into the text fields data2, data2 and data4.

The script should

 

1. Check that none of the fields are blank.

 

2. Add the values to the database if all fields have been filled in / or inform the user that one of the values is missing.

Then use the isset() function with the $_POST[] variables....

 

if ($submit && isset($_POST['data2']) && etc. etc. etc.) {


}

 

Or you can determine what data is being held in one of the variables when you don't input anything (it could be just "" or NULL or whatever)....and then look for that in your IF statement.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.