Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6080627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:05:00+00:00 2026-05-23T11:05:00+00:00

I have a form that populates a database, and I’m having trouble with the

  • 0

I have a form that populates a database, and I’m having trouble with the error handling. I want the errors to show in a small pop up window on the same pg.

    <form id="form1" name="form1" method="post" action="mailform.php" onsubmit="MM_validateForm('Name','','R','Business Name','','R','Email Address','','R','How selling product','','R','Where did you hear about us','','R');return document.MM_returnValue">
    <div style="color:#FF0000; text-align:center;"><?php if(!empty($_GET['err_msg'])){echo $_GET['err_msg'];} ?></div>
        <fieldset>
        <legend>Contact form</legend>
            <p class="first">
                <label for="name">First Name</label>
                <input type="text" name="First Name" id="first_name" size="30" value="<?=htmlentities($profiledata['First_Name'])?>" />
            </p>

        <p class="first">
                <label for="name">Last Name</label>
                <input type="text" name="Last Name" id="last_name" size="30" value="<?=htmlentities($profiledata['Last_Name'])?>" />
            </p>

            <p>
                <label for="name">Phone Number</label>
                <input type="text" name="Phone Number" id="phone number" size="30" value="<?=$profiledata['Phone_Number']?>" />
            </p>
                            <p>
                <label for="email">Business Name</label>
                <input type="text" name="Business Name" id="business name" size="30" value="<?=htmlentities($profiledata['Business_Name'])?>" />
            </p>
                            <p>
                <label for="email">Web Address</label>
                <input type="text" name="Web Address" id="web address" size="30" value="<?=$profiledata['Web_Address']?>" />
            </p>
            <p>
                <label for="email">Email</label>
                <input type="text" name="Email Address" id="email address" size="30" value="<?=$profiledata['Email_Address']?>" />
            </p>
        <p>
            <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
                <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" />
        </p>                
        </fieldset>
        <fieldset>                                                                          
            <p>
                <label for="message">Describe how you plan on selling this product</label>
                <textarea name="How selling product" id="How selling product" cols="30" rows="4"><?=htmlentities($profiledata['How_selling_product'])?></textarea>
            </p>    
            <p>
                <label for="message">Where did you hear about us?</label>
                <textarea name="Where did you hear about us" id="Where did you hear about us" cols="30" rows="4"><?=htmlentities($profiledata['Where_did_you_hear_about_us'])?></textarea>
            </p>                    
        </fieldset>
        <p class="submit"><button type="submit">Send</button></p>

        <input name="mailform_address" type="hidden" value="email@address.com" /> 
  </form>

Error handling:

function valid_email($str)
{
    return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}

function is_url($str)
{
    return ( ! preg_match("/^((www)\.)?((\w+|[\d]?+)+(\.|\-)(\w+[\d]?+))+(\w)$/", $str)) ? FALSE : TRUE;
}

function valid_phone($str)
{
    $Num = $str;
    $Num = ereg_replace("([     ]+)","",$Num);;
    $Num = eregi_replace("(\(|\)|\-|\+)","",$Num);
    if(!is_numeric($Num))
    {       
        return FALSE;
    }   
    else
        return TRUE;
}

$form_field =   array(  
                            'First_Name'                    =>  '',
                            'Last_Name'                     =>  '',
                            'Business_Name'                 =>  '',
                            'Phone_Number'                  =>  '',
                            'Web_Address'                   =>  '',
                            'Email_Address'                 =>  '',
                            'How_selling_product'           =>  '',
                            'Where_did_you_hear_about_us'   =>  '',
                        );
foreach($form_field as $key => $value){$profiledata[$key]=trim($_POST[$key]);}

$_SESSION['profiledata']    =   $profiledata;

$emailto = NULL;
$emailmessage = "Dealer Contact Form\n";
$emailsubject = "Dealer Contact Form";

if(!empty($_POST)){

    //echo "<pre>";print_r($_POST);die;

    if( $_SESSION['security_code'] != $_POST['security_code'] || empty($_SESSION['security_code'] ) ) {

        // Insert your code for showing an error message here
        $err_msg    = 'Sorry, you have provided an invalid security code';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;

    } else {
        unset($_SESSION['security_code']);  
    }

    $fname      =   html_entity_decode(trim($_POST['First_Name']));
    $lname      =   html_entity_decode(trim($_POST['Last_Name']));
    $company    =   html_entity_decode(trim($_POST['Business_Name']));
    $phone      =   html_entity_decode(trim($_POST['Phone_Number']));
    $website    =   html_entity_decode(trim($_POST['Web_Address']));
    $email      =   html_entity_decode(trim($_POST['Email_Address']));
    $notes      =   "Lead Source: ".html_entity_decode(trim($_POST['Where_did_you_hear_about_us']))."\n";
    $notes      .=  "Selling Method: ".html_entity_decode(trim($_POST['How_selling_product']));

    if(!valid_phone($phone)){
        $err_msg    = 'Please enter valid Phone Number.';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;
    }

    if(!is_url($website)){
        $err_msg    = 'Please enter valid Web Address.';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;
    }

    if(!valid_email($email)){
        $err_msg    = 'Please enter valid Email.';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;
    }

    if(!stristr($website,"http://") && !stristr($website,"https://") && $website){
        $website    =   "http://".$website;
    }

    $res    =   mysql_query("SELECT in_customer_id FROM tbl_customer WHERE st_company_name = '".addslashes($company)."'");
    if(mysql_num_rows($res)){   
        $err_msg    =   'Business Name already exists';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;
    }

    $res    =   mysql_query("SELECT st_user_name,st_user_email_id FROM tbl_admin_user WHERE st_user_email_id='".addslashes($email)."' AND flg_is_delete=0");
    if(mysql_num_rows($res)){   
        $err_msg    =   'Email already exists';
        header("Location: reseller.php?err_msg=".urlencode($err_msg));
        return;
    }

I’d appreciate some help or at least a nudge in the right direction. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:05:00+00:00Added an answer on May 23, 2026 at 11:05 am

    Depending on what kind of ‘popup’ you want, you will probably want to implement some client side javascript that displays a nicely formatted message that makes use of the message that you send back from the server.

    I’d look at using JQuery if it was me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this array that populates a dropdown menu. The key is my database
I have a control that, upon postback, saves form results back to the database.
I am designing a database app, and have a form which populates with data
I have an HTML select form that populates my list with elements found in
I have a survey-type form that's being populated from a web database on the
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
I have a PHP page that queries a DB to populate a form for
I have form that displays several keywords (standard set of choice lists that changes
I currently have form that checks if a user has unsubmitted changes when they
I have a form that contains a GridView control which is databound to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.