Have a data entry screen

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
with html and php using mysql.

How do I catch error's from a database like "duplicate entry" and display
something on the entry screen.

Also how do you clear the data boxes on a screen. When I use 'go back on
page' the data remains.


Re: Have a data entry screen

dba wrote:
Quoted text here. Click to load it

It depends on the database.  Check the manual for the calls associated
with your database.

Quoted text here. Click to load it

You can't easily.  Much of the time this doesn't even call the server -
just fetches the page from the local cache.  Of if it does, it calls
with the same POST or GET parameters as before, so your script does the
same thing.

You can try setting a session variable and, if it is set, clear the
values from the screen.  But then when do you reset this variable?

Quoted text here. Click to load it

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Have a data entry screen

contained the following:

Quoted text here. Click to load it

The big problem with preventing duplicate entries is deciding what
exactly constitutes a duplicate.  For instance  Rothesay Ave. could be
the same as Rothesay Avenue.   And Rothsay Avenue may well be the same
too.  Unless you can identify an attribute or set of attributes which
will uniquely identify the record, you may well just have to work round

Sometimes you are only bothered about duplicates due to people
submitting a form twice. To prevent this I save the insert query as a
session variable (you may have to leave out any time sensitive info).
Before the insert I then check against this variable and if they match
show an error message.

I find that starting a session on the form page clears input values form
the form but the downside of this is that users have to add the entries
again if there is an error.  So I store these values temporarily as
session variables.  On a successful insert I clear all the session

So the process is form page->error/successpage (if there is an error
link back to form page)

I use javascript validation to enhance the experience of users with JS
enabled but of course always double check using php before insertion
into the database.

Geoff Berrow  0110001001101100010000000110

Re: Have a data entry screen

Quoted text here. Click to load it

Use a try-catch statement such as this: (example uses PDO)

try {
    $db->Query("ERRONEOUS SQL QUERY");
} catch(Exception $e) {
    // If an error occurs
    echo "We caught the error: " . $e->getMessage();

Site Timeline