fareedreg Posted January 24, 2010 Share Posted January 24, 2010 I am using php with mysql database. I create a form and with the help of submit button i m updating values from textboxes to mysqltable... but the horrible problem occur when i press submit button more than 1 time. IF i press submit buttons 2 time.. the record which it typed enter two times in the table. I m closing mysql after update but the problem remain same... CAN ANY ONE HAVE IDEA.. Here is the code mysql_select_db($Db, $link); $suppid = $q; $bookid = $_POST["txtbook_id"]; $bookname= $_POST["txtbook_name"]; $author = $_POST["txtauthor"]; $genres = $_POST["cmdgen"]; $cost = $_POST["txtcost"]; $discprice = $_POST["txtdisc_price"]; $isbn = $_POST["txtisbn"]; $lang = $_POST["txtlang"]; $query = "INSERT INTO $Tb (supp_id,book_id,book_name,genres,author,cost,disc_price,isbn,lang) value('$suppid','$bookid','$bookname','$genres','$author','$cost','$discprice','$isbn','$lang')"; if(!mysql_query($query, $link)) die ("Mysql error ....<p>".mysql_error()); $id=7; include 'call.php'; ?> <?php echo "<script type='text/javascript'> window.alert('Add Successfully!')</script>"; mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/189619-updating-problem/ Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 I would assume that you have a hidden variable in your form so the submit can be detected, and decide to do the insert. So, why not use the same value to prevent a second submission, by disabling the submit button. There are alternative ways of doing this, but it depends on if you want to re-present the form, or go elsewhere after submission. Link to comment https://forums.phpfreaks.com/topic/189619-updating-problem/#findComment-1000794 Share on other sites More sharing options...
fareedreg Posted January 24, 2010 Author Share Posted January 24, 2010 how to disable submit button after pressing once. Link to comment https://forums.phpfreaks.com/topic/189619-updating-problem/#findComment-1000835 Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 Call a javascript function that document.getElementById('buttonid').disabled=true; Link to comment https://forums.phpfreaks.com/topic/189619-updating-problem/#findComment-1000841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.