Jump to content

On form submit mysql query for name


designop

Recommended Posts

Hello,

 

I have a form script that works great except anyone can submit multiples with nothing to stop them.  I am looking for a way via php that on submit of a form it does a mysql query into my database and checks the name field vs the name field in the database.  Making sure that it is not a duplicate.  If it is, it errors and says, "Sorry you already submitted and cannot submit another".

 

Is this possible?  Is it hard?

 

 

Link to comment
https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/
Share on other sites

you'll need to use javascript

 

/*
* Send post data to the processor page to generate the FDF file.
*/
var obj = new XMLHttpRequest();    
function makePostString(form,address){
	var elem = document.forms[form].elements;
		for (i = 0; i < elem.length; i++) {
			if (i == 0) {
				str = elem[i].name + '=' + elem[i].value;
			}
			else {
				str = str + '&' + elem[i].name + '=' + elem[i].value;
			}
		}
		getName(str,address);
}
function getName(postvals,address){
		obj.open("POST",address,true);
			obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			obj.setRequestHeader("Content-length", postvals.length);
			obj.setRequestHeader("Connection", "close");
			obj.onreadystatechange = function(){
						if (obj.readyState == 4 && obj.status == 200) {
							document.getElementById('pdf-frame').src = obj.responseText;
						}
					}
	       }
		obj.send(postvals);

All you have to do to use this is

<form id="YourForm" action="makePostString('YourForm','YourProcessorPage.php" method="post">

This will submit the form without ever reloading the page.  All you do to get the vars submitted on the processor page is the standard $_POST['YourField'].

 

Cheers!

you're right he doesn't, but this eliminates the need to refresh or go to a different page, it also eliminates the need for error scripts.

 

Also, your Javascript isn't even right...you missed the ) and I don't think you can use Javascript in the action of a form.  I think you need onSubmit.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.