Mac Taylor
Mac Taylor

Reputation: 5148

how to submit a form and show the result in that page

im using a form in php to submit some information into my database

so i used two function to do this

but how to show the result in th same page that has the form

Upvotes: 0

Views: 533

Answers (4)

Your Common Sense
Your Common Sense

Reputation: 157839

it should be shown on the next request.
because your app should perform an HTTP redirect after POST request. it can be same page though

Upvotes: 0

karthi_ms
karthi_ms

Reputation: 5698

To load the same page you have to assign the variable $_SERVER[PHP_SELF] for the form action field.

<form action='$_SERVER[PHP_SELF]?op=ban' method='post'>

then when the page get load you just check the post variable ,if it contains the appropriate data then print the result with the form.(Normally people using div tag to print the results )

Upvotes: 1

Franz
Franz

Reputation: 11553

It's as easy as this:

if (isset($_POST['submit']))
{
    // do something with your data
}

form();

Upvotes: 0

Shoban
Shoban

Reputation: 23016

Forgive me if I am wrong. I think you have copied the code from some where and using it without understanding how forms work.

<form action='index.php?op=ban' method='post'>

The above code says to which page the values should be submitted. As you can see above the values in the form will be submitted to index.php. So the DB operations will(should) happen in index.php and the Thank you message can be shown in index.php.

If you want to show your result in the same page then you will have to submit to the page in which the form resides. But in this case you should have a logic in the page to decide whether the form was submitted or was it loaded first time.

The code snippet in your question does not tell us name of the file the code exists so we wont be able to tell you whether the result will be shown in the same page. Aslo the source code is not complete.

Post a detailed source code and we will be able to help. Hope it helps.

Upvotes: 0

Related Questions