RE: [PHP-DB] Hold that insert!

From: Date: Tue, 27 Mar 2001 17:20:30 +0000
Subject: RE: [PHP-DB] Hold that insert!
Groups: php.db 
Request: Send a blank email to php-db+get-7891@lists.php.net to get a copy of this message
> I like your simplicity and straightforwardness. Thanks. ;p > My code tends toward: > switch($submit) { > case: "Accept": > .. insert record > break; > case: "Delete": > .. delete record > break; > case "Cancel": > .. cancel record changes and return to previous > condition > break; > } If there is the possiblity of processing different functions, I do this: ---------- if( isset( $submit )) { errorChecking(); if( $noErrors ) { switch( $function ) { case "insert": doDBInsert(); $resultPage = "here"; break; case "modify": doDBModify(); $resultPage = "there"; break; case "delete": doDBDelete(); $resultPage = "over"; break; } header( "location: $resultPage" ); exit(); } // end if( $noErrors ) showErrors(); } // end if( isset( $submit )) displayForm(); ------ Just as before, but doing different things depending on function. That way, the code is still only run when the form submits. And still, if there are any errors, the same code is run to (re)display the form. And since all the POST vars are passed through, the form elements poplulate them selves with the data that the user previously entered so the user loses nothing. I rarely display results on the same page. This allows me to keep it a little more modular and if I ever need to modify one, I don't have to worry about touching the other. Just out of principle, I like to keep as few ELSEs on a page as possible. Generally, if you look at the code, you can streamline things alot just by getting rid of some of the ELSE statements.

« previous php.db (#7891) next »