designop Posted September 12, 2008 Share Posted September 12, 2008 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 More sharing options...
tmbrown Posted September 12, 2008 Share Posted September 12, 2008 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! Link to comment https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/#findComment-640169 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 Lol, he doesn't need Ajax for this. Check for duplicate entries in the database before inserting. Link to comment https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/#findComment-640172 Share on other sites More sharing options...
tmbrown Posted September 12, 2008 Share Posted September 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/#findComment-640175 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/#findComment-640178 Share on other sites More sharing options...
tmbrown Posted September 13, 2008 Share Posted September 13, 2008 yeah you can actually, i use it at work: http://dev.tserver.net/pdfgen. As far as the ')', my mistake. It would be <form id="YourForm" action="javascript:makePostString('YourForm','YourProcessorPage.php');" method="post"> Link to comment https://forums.phpfreaks.com/topic/124001-on-form-submit-mysql-query-for-name/#findComment-640233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.