Update Form + Update Query in one file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Update Form + Update Query in one file

Post 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
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Code: Select all

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

// rest of script
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

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