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 8503949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:53:40+00:00 2026-06-11T01:53:40+00:00

I wonder if you can help me please. I am passing data from a

  • 0

I wonder if you can help me please. I am passing data from a html form into a MySQL DB using PHP. All fields have been validated but I want it to validate all the data before any of it goes into the DB.

For example, if there are not enough characters entered in the ‘name’ field it will tell the user, however if the email address is correctly validated it then inserts the data into the DB. How would I go about doing that?

    // check the length of 'name' field if between 2 and 50 characters

    if ((strlen($name) < 2 || strlen($name) > 50)) {
        echo "The name is invalid, must be between 2 and 50 chearacters.";
        exit;

    }

    echo "</br>";

    // check field name contains numbers
    if (preg_match('#[0-9]#',$name)){ 

        echo 'The name is invalid, its contains numbers. Please go back and try again.';
    }  

    echo "</br>";

    // Check if email is valid. If not tell the user it is invalid

    $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; 
    if (!preg_match($regex, $emailaddress)) {
            echo "Invalid email address. Please go back and try again.";
    }

  // insert the data from the registration form into the DB  
  mysql_query("INSERT into customers 
      (cs_name, cs_emailaddress) 
      VALUES
  (
  '".$name."', '".$emailaddress."',
  )
  ")
  or die(mysql_error()); 
  • 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-06-11T01:53:42+00:00Added an answer on June 11, 2026 at 1:53 am

    You make the script die before mysql_query() is called, or you create a $isValid variable initially true that you set to false when something goes wrong. And you put a condition before mysql_query:

    if ($isValid === true)
    {
        mysql_query(...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone can help me please. I'm using the following script to
I wonder whether someone can help me please. I've created this form which allows
I wonder whether someone can help me please. I'm using the code below to
I wonder whether someone can help me please. I have a mySQL database which
I wonder whether someone can help me please. I'm using the following script to
I wonder if anyone could please help me I have been using HTML tidy
I wonder if someone can help: Long story short, I'm using MSSQL2005 to build
I wonder whether someone could help me please, From a tutorial I found online
I wonder whether someone can help me please. I'm trying to implement the mysql_insert_id()
I wonder whether someone can help me please. I've put together this page, which

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.