MukulAgr
MukulAgr

Reputation: 291

post method not working on condition

I have created a page on which a form posts its value. So I add some lines to get those values like

$parameter = mysqli_real_escape_string($con,$_POST['Parameter']);

But when I open that page without that form it shows Notice that Undefined index parameter in page on line.

So I want to make something like if I post the values then only specific area will work. Otherwise remaining area will work just like if condition.

For ex.

if(post)
{}
else
{}

How can I do this?

Upvotes: 0

Views: 70

Answers (3)

Prateek
Prateek

Reputation: 368

You can use isset() function. In your case if should be like

if(isset($_POST['param']))
{
 //Do something
}
else
{
 //Do something else
}

Upvotes: 2

MH2K9
MH2K9

Reputation: 12039

Use isset() to check

if(isset($_POST['Parameter'])){
    //desired tasks
    //$parameter = mysqli_real_escape_string($con,$_POST['Parameter']);
}else{
    //other task
}

Upvotes: 2

Avinash Babu
Avinash Babu

Reputation: 6252

First you would need to check if the values are set properly..You can do it with the if condition which would be like

if(isset($_POST) && array_key_exists('name_of_your_submit_input',$_POST)){
// do the things after form processing
}else{
//things you want to do after form breaks.
}

Upvotes: 2

Related Questions