0

We often see in a standard input form that , if the values do not match the input criteria , then ,come whatever may , even after clicking on the submit button the data is not inserted into database.The question is, how do you prevent erroneous data from entering into the table.

2
  • What you exactly wanna ask? At once you are saying "data is not inserted in database?" and at other side you are asking "how to prevent data from entering the table?". Don't you think you have solved your problem in your question itself. Commented Jan 11, 2011 at 5:01
  • it is called data validation, and you usually check if the data is correctly formatted and safe before trying to insert it into the database or do anything with it. Commented Jan 11, 2011 at 5:05

2 Answers 2

1

Data can be validated "server-side" or "client-side". If what you want is to validate it BEFORE sending it to the server, then what you need is a "client-side" validation. In order to do that, you need to use Javascript (see: Form validation with Javascript).

Even if you validate your data with Javascript, this won't prevent inserting erroneous data into your Database (for example, javascript may not be enabled in the client). For this, you need "server-side" validation using php.

For better results, use both. Javascript will prevent sending erroneous data every time (less load for your server) and PHP will help you to keep your data reliable.

Sign up to request clarification or add additional context in comments.

1 Comment

agreed, so i posted client side validation
0

have some javascript or python filter so an onSubmit() function occurs before actual submission

e.g.

<input type="submit" onsubmit="submitFunc()" />

where submitFunc() is defined earlier on

<script type="text/javascript">

function submitFunc(username, password) {

if (!username) {

document.write("Uh oh! username not valid!")

}

if (!password) {

document.write("Uh oh! password not valid!")

}

}

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.