Jump to content


Help with my script

  • Please log in to reply
1 reply to this topic

#1 zimmo

  • Members
  • PipPipPip
  • Advanced Member
  • 160 posts

Posted 04 May 2006 - 03:21 PM

I have put together a script for error checking and once I have this working I can complete the rest.

This is the set up

1: User enters the site and clicks a link which contains a random identifier number of 12 characters.

2: The first part of the form is Personal Details.

3: When they enter the personal details I need a kind of error check, so that when they fill in the details if they miss anything, they are taken back to the form to fill in.

My problem;
I know you can set up this if the form posts to itself (same page), but my application does not work like this.

Before the error checking I just had the form post to a script and that processed the data and then redirected them to the next step of the form. Now I need to error check the data and still perform the same, either insert the data into the database or if errors take them back to the form with the field errors.

Now this script needs some work, as at present I get a parse error on my else statement.

I am very tired trying to get this to work. Please if anyone can help be appreciated.

basically I need this to check the form elements, if correct enter in the database, if incorrect back to form to fill in wrong or missing elements.

//# Include the connections script to make a database connection.


//# Error Checking For the Personal Details section of the quote
//# The form should post to itself.

if ( $_POST['submit'] ) {

$valid = 1;

//# The fields all follow this patern.
//# If you do not require an error check for a field then just use the
//# post field method and not the error check method

$main_title = $_POST['main_title'];

$main_firstname = $_POST['main_firstname'];
if ( empty($main_firstname) ) {
$valid = 0;
$main_firstname_error = 'You did not enter your First Name';

$main_surname = $_POST['main_surname'];
if ( empty($main_surname) ) {
$valid = 0;
$main_surname_error = 'You did not enter your Surname';

$main_dob = $_POST['main_dob'];
if ( empty($main_dob) ) {
$valid = 0;
$main_dob_error = 'You did not enter your Date of Birth';

$main_maritalstatus = $_POST['main_maritalstatus'];

$main_fulllicence = $_POST['main_fulllicence'];

$main_taxibadge = $_POST['main_taxibadge'];

$main_residency = $_POST['main_residency'];

$main_house = $_POST['main_house'];
if ( empty($main_house) ) {
$valid = 0;
$main_house_error = 'You did not enter your House Number';

$main_postcode = $_POST['main_postcode'];
if ( empty($main_postcode) ) {
$valid = 0;
$main_postcode_error = 'You did not enter a Postcode';

// End of error checking for the Personal Details Fields, all fields covered.

if ( $valid == 1 ) {

        # setup SQL statement
        $SQL = " INSERT INTO personal_details ";
        $SQL = $SQL . " (sid, main_title, main_firstname, main_surname, main_dob, main_maritalstatus, main_fulllicence, main_taxibadge, main_residency, main_house, main_postcode) VALUES ";
        $SQL = $SQL . " ('$sid', '$main_title', '$main_firstname', '$main_surname', '$main_dob', '$main_maritalstatus', '$main_fulllicence', '$main_taxibadge', '$main_residency', '$main_house', '$main_postcode') ";

        #execute SQL statement
        $result = mysql_db_query( *****,"$SQL",$connection );

        # check for error
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

    header("Location: http://www.*****.co.uk/quote/adddrivers/index.php?sid=$sid");
    header("Location: http://www.*****.co.uk/quote/personal.php?sid=$sid");



#2 craygo

  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 04 May 2006 - 04:31 PM

You can do it with javascript before the form is submitted. I use it to check my fields before they are submitted. This only works if you want to make sure they are not blank or if you want to follow a certain format. It will not check anything against a database or anything like that.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users