Page 1 of 1

Update Form + Update Query in one file

Posted: Thu Jul 20, 2006 6:10 pm
by thiscatis
Hi,

Can anyone help me with a problem?

The thing is : I want the query & the update form in the same file.

So when there's POST data the query will run and alter the records in my database, and then show the new results
So when there IS NO POST data the page will just show the update form.

Is this possible?

// I think the form action should be something like

Code: Select all

action="<?php echo $_SERVER['PHP_SELF']?>"
But how do I tell the script only to update the records when there's POST data?
Otherwise it will empty the records when there's no data

Posted: Thu Jul 20, 2006 6:18 pm
by daedalus__

Code: Select all

if ($_POST) // do better validation than this
{
   // do something
}

// rest of script

Posted: Thu Jul 20, 2006 6:19 pm
by Weirdan

Code: Select all

if(count($_POST)) {
 // process data
} else {
 // show the form
}