Jump to content

Posting Data to a Database AFTER A submit / confirm button is pressed?


Recommended Posts

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?

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>

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()));
}
?>

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... ???

 

 

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"

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>

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">

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
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.