stublackett Posted September 17, 2008 Share Posted September 17, 2008 Hi, I've got an order confirmation form, When the customer presses the submit button I'd then like to INSERT the post values into the Database I've currently got Code in place, But the data seems to be inserted straight off, Before the submit button is pressed The form HTML is <input type=submit value="Confirm and Purchase" name="submit"> The PHP is : <?php // check if the form has been submitted if(isset($_POST['submit'])) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> Is this the right way of doing it, Or am I missing something somewhere or other? Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/ Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 Do you have a else statement after the If statement saying display the form instead of the post values? Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643687 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 also instaed of if(isset($_POST['submit'])) put if($_POST['submit']) Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643688 Share on other sites More sharing options...
stublackett Posted September 17, 2008 Author Share Posted September 17, 2008 Do you have a else statement after the If statement saying display the form instead of the post values? I dont..... The form is quite a simple one, How would I structure it? HTML is <!-- The first line of code creates a form, which has the POST method and its action is to send the form to us. You do not need to set-up a special connection to us before using it - your Internet connection is all you need to communicate with us.--> <form action="https://select.worldpay.com/wcc/purchase" method=POST> <!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --> <input type=hidden name="instId" value="HIDDEN" /> <!-- Hidden for posting purposes --> <!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --> <input type=hidden name="cartId" value="Keeper for a day"> <!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --> <input type=hidden name="amount" value="<?php echo $total ; ?>"> <!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --> <input type=hidden name="currency" value="GBP"> <!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --> </p> <p align="left" class="style13"> <input type=submit value="Confirm and Purchase" name="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643695 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 You need to state what the form is supposed to send data to. You haven't specified the exact file. Need to be specific i.e <form action="https://select.worldpay.com/wcc/purchase/results.php" method=POST> Then is the file you send the variable to have this <?php // check if the form has been submitted if($_POST['submit']) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643717 Share on other sites More sharing options...
stublackett Posted September 17, 2008 Author Share Posted September 17, 2008 Totally stumped...... Code is currently looking like : <?php // check if the form has been submitted if($_POST['submit']) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) //VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> <!-- The first line of code creates a form, which has the POST method and its action is to send the form to us. You do not need to set-up a special connection to us before using it - your Internet connection is all you need to communicate with us.--> <form action="https://select.worldpay.com/wcc/purchase/results.php" method=POST> <!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --> <input type=hidden name="instId" value="" /> <!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --> <input type=hidden name="cartId" value="Keeper for a day"> <!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --> <input type=hidden name="amount" value="<?php echo $total ; ?>"> <!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --> <input type=hidden name="currency" value="GBP"> <!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --> Surely that should work... ??? i.e <form action="https://select.worldpay.com/wcc/purchase/results.php" method=POST> The total is passed onto WorldPay for the user to purchase their tickets... So that shouldnt have a bearing on that as such? I just basically need the Database Insertion Command to run as soon as the user clicks "Confirm & Purchase" Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643806 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 post all the code, Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643809 Share on other sites More sharing options...
stublackett Posted September 17, 2008 Author Share Posted September 17, 2008 Here ya go...... <?php //Collect Post Vars extract($_POST); //Number of people change to Integer Value $numberofpeople = $_POST['os']; if ( $numberofpeople == "one" ) { $numberofpeople = 1; } if ( $numberofpeople == "two" ) { $numberofpeople = 2; } if ( $numberofpeople == "three" ) { $numberofpeople = 3; } if ( $numberofpeople == "four" ) { $numberofpeople = 4; } // Weekend or Weekday $daychoice = $_POST['daychoice']; if ( $daychoice == "Week Day" ) { $daychoice = 160; } if ( $daychoice == "Weekend" ) { $daychoice = 190; } //For Postage & Packaging if ( $numberofpeople >= "1") { $postage = 1; } //Calculate Total $reducedrate = $_POST['reduced_rate']; $newrate = 8.00 * $reducedrate; $total = $daychoice * $numberofpeople + $newrate + $postage; $total = number_format($total,2); //Set Description $description = "Keeper For A Day"; echo "<b>You Submitted As The Sender : </b>"; echo $postage; echo "<br><br>"; echo "Name : "; echo $sendertitle; echo " "; echo $senderforename; echo " "; echo $sendersurname; echo "<br><br>"; echo "Address : "; echo $senderaddress; echo " "; echo $senderaddress1; echo " "; echo $sendertown; echo " "; echo $sendercounty; echo "<br><br>"; echo "Telephone : "; echo $sendertelephone; echo "<br><br>"; echo "E-Mail Address : $senderemail"; echo "<br><br>"; echo "This gift is for : $numberofpeople person(s)"; echo "<br><br>"; echo "This also includes $reducedrate people entering the park at a reduced rate"; echo "<br><br><br>"; echo "<b>Total Cost for this purchase : </b>"; echo "£"; echo $total; ?> <?php // check if the form has been submitted if($_POST['submit']) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) //VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> <!-- The first line of code creates a form, which has the POST method and its action is to send the form to us. You do not need to set-up a special connection to us before using it - your Internet connection is all you need to communicate with us.--> <form action="https://select.worldpay.com/wcc/purchase/results.php" method=POST> <!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --> <input type=hidden name="instId" value="" /> <!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --> <input type=hidden name="cartId" value="Keeper for a day"> <!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --> <input type=hidden name="amount" value="<?php echo $total ; ?>"> <!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --> <input type=hidden name="currency" value="GBP"> <!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --> </p> <p align="left" class="style13"> <input type=submit value="Confirm and Purchase" name="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643810 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 try this <?php //Collect Post Vars extract($_POST); //Number of people change to Integer Value $numberofpeople = $_POST['os']; if ( $numberofpeople == "one" ) { $numberofpeople = 1; } if ( $numberofpeople == "two" ) { $numberofpeople = 2; } if ( $numberofpeople == "three" ) { $numberofpeople = 3; } if ( $numberofpeople == "four" ) { $numberofpeople = 4; } // Weekend or Weekday $daychoice = $_POST['daychoice']; if ( $daychoice == "Week Day" ) { $daychoice = 160; } if ( $daychoice == "Weekend" ) { $daychoice = 190; } //For Postage & Packaging if ( $numberofpeople >= "1") { $postage = 1; } //Calculate Total $reducedrate = $_POST['reduced_rate']; $newrate = 8.00 * $reducedrate; $total = $daychoice * $numberofpeople + $newrate + $postage; $total = number_format($total,2); //Set Description $description = "Keeper For A Day"; echo "<b>You Submitted As The Sender : </b>"; echo $postage; echo "<br><br>"; echo "Name : "; echo $sendertitle; echo " "; echo $senderforename; echo " "; echo $sendersurname; echo "<br><br>"; echo "Address : "; echo $senderaddress; echo " "; echo $senderaddress1; echo " "; echo $sendertown; echo " "; echo $sendercounty; echo "<br><br>"; echo "Telephone : "; echo $sendertelephone; echo "<br><br>"; echo "E-Mail Address : $senderemail"; echo "<br><br>"; echo "This gift is for : $numberofpeople person(s)"; echo "<br><br>"; echo "This also includes $reducedrate people entering the park at a reduced rate"; echo "<br><br><br>"; echo "<b>Total Cost for this purchase : </b>"; echo "£"; echo $total; ?> <?php // check if the form has been submitted if($_POST['submit']) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) //VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); } ?> <!-- The first line of code creates a form, which has the POST method and its action is to send the form to us. You do not need to set-up a special connection to us before using it - your Internet connection is all you need to communicate with us.--> <form action="https://select.worldpay.com/wcc/purchase/results.php" method=POST> <!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --> <input type=hidden name="instId" value="" /> <!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --> <input type=hidden name="cartId" value="Keeper for a day"> <!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --> <input type=hidden name="amount" value="<?php echo $total ; ?>"> <!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --> <input type=hidden name="currency" value="GBP"> <!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --> </p> <p align="left" class="style13"> </form> <input type=submit value="Confirm and Purchase" name="submit"> Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643827 Share on other sites More sharing options...
stublackett Posted September 17, 2008 Author Share Posted September 17, 2008 No joy.... Its just inserting the Values as soon as the page is loaded Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643831 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 try <?php //Collect Post Vars extract($_POST); //Number of people change to Integer Value $numberofpeople = $_POST['os']; if ( $numberofpeople == "one" ) { $numberofpeople = 1; } if ( $numberofpeople == "two" ) { $numberofpeople = 2; } if ( $numberofpeople == "three" ) { $numberofpeople = 3; } if ( $numberofpeople == "four" ) { $numberofpeople = 4; } // Weekend or Weekday $daychoice = $_POST['daychoice']; if ( $daychoice == "Week Day" ) { $daychoice = 160; } if ( $daychoice == "Weekend" ) { $daychoice = 190; } //For Postage & Packaging if ( $numberofpeople >= "1") { $postage = 1; } //Calculate Total $reducedrate = $_POST['reduced_rate']; $newrate = 8.00 * $reducedrate; $total = $daychoice * $numberofpeople + $newrate + $postage; $total = number_format($total,2); //Set Description $description = "Keeper For A Day"; echo "<b>You Submitted As The Sender : </b>"; echo $postage; echo "<br><br>"; echo "Name : "; echo $sendertitle; echo " "; echo $senderforename; echo " "; echo $sendersurname; echo "<br><br>"; echo "Address : "; echo $senderaddress; echo " "; echo $senderaddress1; echo " "; echo $sendertown; echo " "; echo $sendercounty; echo "<br><br>"; echo "Telephone : "; echo $sendertelephone; echo "<br><br>"; echo "E-Mail Address : $senderemail"; echo "<br><br>"; echo "This gift is for : $numberofpeople person(s)"; echo "<br><br>"; echo "This also includes $reducedrate people entering the park at a reduced rate"; echo "<br><br><br>"; echo "<b>Total Cost for this purchase : </b>"; echo "£"; echo $total; ?> <?php // check if the form has been submitted if($_POST['submit']) { $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail,numberofpeople,numberforreducedrate,total) //VALUES ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail','$os','$reducedrate','$total')"; ($result = mysql_query($sql ,$conn) or die(mysql_error())); echo 'success'; } else { ?> <!-- The first line of code creates a form, which has the POST method and its action is to send the form to us. You do not need to set-up a special connection to us before using it - your Internet connection is all you need to communicate with us.--> <form action="https://select.worldpay.com/wcc/purchase/results.php" method=post> <!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --> <input type=hidden name="instId" value="" /> <!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --> <input type=hidden name="cartId" value="Keeper for a day"> <!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --> <input type=hidden name="amount" value="<?php echo $total ; ?>"> <!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --> <input type=hidden name="currency" value="GBP"> <!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --> </p> <p align="left" class="style13"> </form> <input type=submit value="Confirm and Purchase" name="submit"> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124632-posting-data-to-a-database-after-a-submit-confirm-button-is-pressed/#findComment-643840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.