|
Posted by Breklin on 10/17/06 20:01
Hello again Linda,
You will need to run a validation of each field to see it is empty or
not. Simple enough. I will give you the most basic format to do this.
<?php
// Set default error flags.
$is_error = false;
$is_error_field_name = false;
// Check to see if Fields are Empty
// If true, flag error boolean
if(empty($_POST['field_name'])){
$is_error = true;
$is_error_field_name = true;
}
// Place this where your error message belongs in your mark up. I
usually create an include file and place it above the form.
// General form error
if($is_error)
echo '<p class="error">Oops! There is a problem. Make sure all
your fields are completed.</p>';
// Custom form error
if($is_error_form_field)
echo '<p class="error">• There appears to be problem with
FORM_FIELD_NAME.</p>';
?>
As a general rule, I tend to place my validation and insert/update code
into the upper area of the document. This keeps everything in one file:
validation, processing, the form, error messaging and successful
confirmation. Using the flags set in the error validation section, I can
tell the script what to display after the form has been submitted.
Is this any clearer?
linda wrote:
> ".:[ ikciu ]:." <no@mail.com> wrote in message
> news:eh3195$j3n$1@news.dialog.net.pl...
>
>> Hmm Steve <no.one@example.com> wrote:
>>
>
>
>> maybe yes and maybe not, i hate so simple question which post lazy ppl who
>> won't try to search it in M or just in google
>>
>>
>
> Ikciu,
>
> I'd just like to clarify I did actually do a search for this, and did not
> find any examples of code that explained how to impliment it, just snipets.
> If I was a little further down the road in understanding php, these would
> have been fine, but as I've only just started out learning, they didn't help
> me.
>
> I also spent many hours trying AND re-trying to write my own code, which can
> be very frustrating. Hence why I asked. I didn't ask anyone to "please can
> you alter my code so that it will produce an error message if a duplicate
> exhists" I ask "could someone please explain how to write an error message
> into my AddNew.php below" As in could some explain what I need to be
> looking for, to resolve my problem. I would have been more than happy if
> someone had said, "look into doing this before your INSERT query".
>
> I'm not looking for a free lunch, just some sugestions on what to have!
>
> Best wishes,
> Linda
>
>
>
[Back to original message]
|