RE: [PHP-DB] Hold that insert!

2001-03-27 Thread Boget, Chris

> 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.



Re: [PHP-DB] Hold that insert!

2001-03-27 Thread Terry Romine

I like your simplicity and straightforwardness.

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($submit) {
show form
} else {
show list
}

where list is a display of the records in the database (browse) and the form is a one 
record dataentry/modification/delete form.

On Tuesday, March 27, 2001, at 10:46 AM, Boget, Chris wrote:

> I do something similar.  However, my layout is like this: 
>  
> -- 
>  
>   if( isset( $submit )) { 
> errorChecking(); 
>  
> if( $noErrors ) { 
>   doDBInsert(); 
>   header( "location: blah" ); 
>   exit(); 
>  
> } // end if( $noErrors ) 
> showErrors(); 
>  
>   } // end if( isset( $submit )) 
>  
>   displayForm(); 
>  
>  


In Light and Love
EaTrom
Order of Melchizedek
Michael's Legions
-
EaTrom's Site:  http://www.blazing-trails.com
Spirituality & Conspiracy
-

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] Hold that insert!

2001-03-27 Thread Boget, Chris

> Click Here! "), so in that case I display the form.  If it does not have
an
> empty value, the user has clicked the submit button, so I can go ahead
> processing the form data.  Like this:
> if ( empty($submit) )
> {
> ### Display the form
> }
> else
> {
> ### Do some checks to make the the data is OK
> 
> ### Do the Insert, or whatever else is to be done
> }

I do something similar.  However, my layout is like this:

--

  if( isset( $submit )) {
errorChecking();

if( $noErrors ) {
  doDBInsert();
  header( "location: blah" );
  exit();

} // end if( $noErrors )
showErrors();

  } // end if( isset( $submit ))

  displayForm();

--

This accomplishes a few things:

* The code is easier to follow
* If there is an error in the form, the errors display and the
form re-displays.  There is only one section of code that deals
with the form, not two as there would be in an IF/ELSE situation.

But then, this is just me. :)

Chris



Re: [PHP-DB] Hold that insert!

2001-03-27 Thread Darryl Friesen

> I have the insertRecord function which is supposed to be called only
> when you hit submit. For some reason I'm blanking out on how to do
> this. The function and function call ARE on the same page. I think I
> just need some logic to indicate "stop" and "go".

Every form has a submit button right?  Submit buttons are form elements
(whose value is submitted when the button is clicked), just like any other
form field.  So I have something like this:

   

In my PHP code, I check the value of $submit; if it's empty, I know the form
data hasn't been submitted yet (if it had, $submit would have the value "
Click Here! "), so in that case I display the form.  If it does not have an
empty value, the user has clicked the submit button, so I can go ahead
processing the form data.  Like this:

if ( empty($submit) )
{
### Display the form
}
else
{
### Do some checks to make the the data is OK

### Do the Insert, or whatever else is to be done
}



- Darryl

 --
  Darryl Friesen, B.Sc., Programmer/Analyst[EMAIL PROTECTED]
  Education & Research Technology Services, http://gollum.usask.ca/
  Department of Computing Services,
  University of Saskatchewan
 --
  "Go not to the Elves for counsel, for they will say both no and yes"



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]