Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-21-2008, 03:04 PM Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I have a script that is basically a shopping cart for one item. It works, but I want to add a print page on the end basically, where it displays the prices, the delivery address and billing address which have been submitted by the user.

Although I don't know how I would do this, I can easily display the addresses because its on the previous page, but the prices are different. Can someone help me display this?

The part which is where it'll be displayed is where $action == billship2

PHP Code:

<?

include ('form.php');

$itemprice "10.00"
$siteurl "index2.php";
$merchantid "redsun01";

$action $_REQUEST["act"];
$display ''//DO NOT EDIT THIS

//Database Connection Information (not displayed for security reasons)

// ------ ID GENERATOR ------
function str_idgen($minlength$maxlength$useupper$usenumbers){
$charset "abcdefghijklmnopqrstuvwxyz";
    if (
$useupper){ $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";}
    if (
$usenumbers){ $charset .= "0123456789";}
    if (
$minlength$maxlength){
        
$length mt_rand ($maxlength$minlength);
    } else {
        
$length mt_rand ($minlength$maxlength);
    }
for (
$i=0$i<$length$i++){ $key .= $charset[(mt_rand(0,(strlen($charset)-1)))]; }
return 
$key;
}
// ------ ID GENERATOR ------


//++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
if ($action == "display") {

$display .='<form name="form1" method="post" action="'.$siteurl.'?act=billship1">';
    
$shippingc $_POST["shipping"];
    if(
$shippingc 1) { echo '<b>ERROR!</b> Please Go Back, and select shipping method.'; exit(); }

    
$quantity $_POST["quantity"];

    
$grandtotal = ($itemprice*$quantity)+$shippingc;
    
$grandtotal number_format($grandtotal2);

    
$display .='<br><img src="http://gks.uk.com/images/book-cover4.jpg"><br><br>';
    
$display .='<u>An Ancient World in Chaos</u>';
    
$display .='<br><br>Item Price: £'.$itemprice;
    
$display .='<br>Quantity: '.$quantity;
    
$display .='<br>Shipping Cost: £'.$shippingc;
    
$display .='<br><br><b>Total: </b> £'.$grandtotal;
                
    
$display .='<br><br><input type="submit" name="Submit" value="Continue">';
    
$display .='</form>';

    
//Make sure we got a record
        
$insertquery "INSERT INTO transactions (transid, quantity, shipping, total) VALUES('".$secrettransid."', '".$quantity."', '".$shippingc."', '".$grandtotal."')";
        
mysql_query($insertquery) or die(mysql_error());

//++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
} elseif ($action == "complete"){

    
$rettrantsid $_REQUEST["trans_id"];
    
$retauth $_REQUEST["auth_code"];
    
$retdatacheck $_REQUEST["cv2avs"];
    
$retammountpaid $_REQUEST["amount"];
    
$retcode $_REQUEST["code"];
    
$retsechash $_REQUEST["hash"];

    
$retdeclined $_REQUEST["message"]; //DECLINED info
    
$retdeclinedcode $_REQUEST["resp_code"]; //2,83 = refferal | 5,54 = not authorised | 30 = general error, retry

    //Update Payment Info
    
if($retdeclined){
        
$thesets "status = '2', retauth = '".$retauth."', retdatacheck = '".$retdatacheck."', retammountpaid = '".$retammountpaid."', retcode = '".$retcode."', retsechash = '".$retsechash."', retdeclined = '".$retdeclined."', retdeclinedcode = '".$retdeclinedcode."'";
        
$display .='<b>ORDER FAILED</b>, We have recieved basic notificatioton why. Email webmaster to locate the problem. (E.G. Miss typed address, postcode).<br>Thanks!';
    } else {
        
$thesets "status = '1', retauth = '".$retauth."', retdatacheck = '".$retdatacheck."', retammountpaid = '".$retammountpaid."', retcode = '".$retcode."', retsechash = '".$retsechash."', retdeclined = '".$retdeclined."', retdeclinedcode = '".$retdeclinedcode."'";
        
$display .='<h3>Thank you for your payment, you will recieve a confirmation email shortly. <br><br>Your transaction id is</h3><h4> '.$rettrantsid.'</h4><br><h3>If you wish to contact us about your order</h3>';
    }
    


//++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --


elseif (
$action == billship1) {

   
$display.= $billingfields;
   
$display.= $shippingfields;
    
    
}

elseif (
$action == 'billship2') {

    if (empty(
$_POST['bill_name']) || empty($_POST['bill_addr_1']) || empty($_POST['bill_state']) || empty($_POST['bill_city']) || empty($_POST['bill_post_code']) || empty($_POST['bill_tel']) || empty($_POST['bill_email']) || $_POST['bill_country'] == '- - Country - -') { $display .= '<span style="font-size: 16px; color: #FF8000;">Some fields were left empty, please fill in the form again.</span><br><br>';
    
      
$display.= $billingfields;
    
$display.= $shippingfields;
 
     } 
    
    else {
    
    
$bname $_POST['bill_name'];
    
$baddr1 $_POST['bill_addr_1'];
    
$baddr2 $_POST['bill_addr_2'];
    
$bcity $_POST['bill_city'];
    
$bstate $_POST['bill_state'];
    
$bcountry $_POST['bill_country'];
    
$bpostc $_POST['bill_post_code'];
    
$btel $_POST['bill_tel'];
    
$bmail $_POST['bill_email'];
    
    
$secrettransid str_idgen(41011);

       
$display .= 'Transaction ID:'.$secrettransid;
    
$display .= '<br><br>Billing Details<br>';
    
$display .= '<br>Name: '.$bname;
    
$display .= '<br>Address Line 1: '.$baddr1;
    
$display .= '<br>Address Line 2: '.$baddr;
    
$display .= '<br>City: '.$bcity;
    
$display .= '<br>County / State / Province: '.$bstate;
    
$display .= '<br>Country: '.$bcountry;
    
$display .= '<br>Post / Zip Code: '.$bpostc;
    
$display .= '<br>Telephone: '.$btel;
    
$display .= '<br>Email: '.$bmail;
    
    
$sname $_POST['ship_name'];
    
$saddr1 $_POST['ship_addr_1'];
    
$saddr2 $_POST['ship_addr_2'];
    
$scity $_POST['ship_city'];
    
$sstate $_POST['ship_state'];
    
$scountry $_POST['ship_country'];
    
$spostc $_POST['ship_post_code'];
    
$stel $_POST['ship_tel'];
    
$smail $_POST['ship_email'];

       if (empty(
$_POST['ship_name']) && empty($_POST['ship_addr_1']) && empty($_POST['ship_state']) && empty($_POST['ship_city']) && empty($_POST['ship_post_code']) && empty($_POST['ship_tel']) && empty($_POST['ship_email']) && $_POST['ship_country'] == '- - Country - -') {} 
    
    else { 
    
$display .= '<br><br>Shipping Details<br>';
    
$display .= '<br>Name: '.$sname;
    
$display .= '<br>Address Line 1: '.$saddr1;
    
$display .= '<br>Address Line 2: '.$saddr;
    
$display .= '<br>City: '.$scity;
    
$display .= '<br>County / State / Province: '.$sstate;
    
$display .= '<br>Country: '.$scountry;
    
$display .= '<br>Post / Zip Code: '.$spostc;
    
$display .= '<br>Telephone: '.$stel;
    
$display .= '<br>Email: '.$smail;
    
    }
    
    }
    
}

elseif (
$action == 'print') {

$bname $_POST['bill_name'];
$baddr1 $_POST['bill_addr_1'];
$baddr2 $_POST['bill_addr_2'];
$bcity $_POST['bill_city'];
$bstate $_POST['bill_state'];
$bcountry $_POST['bill_country'];
$bpostc $_POST['bill_post_code'];
$btel $_POST['bill_tel'];
$bmail $_POST['bill_email'];

    
$display .= 'Item Price: £'.$itemprice;
    
$display .= '<br>Quantity: '.$quantity;
    
$display .= '<br>Shipping Cost: £'.$shippingc;
    
$display .= '<br><br><b>Total: </b> £'.$grandtotal;
    
$display .= 'Transaction ID: '.$secrettransid;
    
$display .= '<br><br>Billing Details<br>';
    
$display .= 'Name: '.$bname;
    
$display .= 'Address Line 1: '.$baddr1;
    
$display .= 'Address Line 2: '.$baddr;
    
$display .= 'City: '.$bcity;

}


else {
    
$display .='<br><img src="http://gks.uk.com/images/book-cover4.jpg"><br><br>';
    
$display .='<form name="form1" method="post" action="'.$siteurl.'?act=display">';
    
$display .='<h2>Select Shipping:</h2>';
    
$display .='<select name="shipping">';
    
$display .='<option value="0" selected>- Select Shipping -</option>';
    
$display .='<option value="1.70">United Kingdom (£1.70)</option>';
    
$display .='<option value="2.00">Europe (£2.00)</option>';
    
$display .='<option value="4.70">Rest of World (£4.70)</option>';
    
$display .='</select><br><br>';
    
$display .='<h2>Quantity:</h2>';
    
$display .='<input name="quantity" type="text" value="1" size="4"><br><br>';
    
$display .='<input type="submit" name="Submit" value="Continue"><br>';
    
$display .='</form>';
}
?>
<?php 
include('/websites/LinuxPackage02/gk/s_/uk/gks.uk.com/public_html/includes/config.php'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The God King Scenario </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php echo $css?>

</head>

<body>

<?php 
echo $construct;
echo 
$header2
include 
$nav2 

 
?>
<center><div id="heading">
  <p>&nbsp;</p>
  <p><img src="http://gks.uk.com/images/shop.jpg"></p>
</div>
</center>
<center>
<div class="style18 style19" id="main-contact" align="left"><br><br>
<?
if($display){
echo 
$display;
echo 
'<br><br><div style="margin-left:10%;"><img src="http://www.secpay.com/starter/sm_mastercard.gif" alt="Master Card" height="50" width="83">';
echo 
'<img src="http://www.secpay.com/starter/sm_visa.gif" alt="Visa" height="50" width="80">';
echo 
'<img src="http://www.secpay.com/starter/sm_maestro.jpg" alt="Maestro" height="50" width="84">';
echo 
'<img src="http://www.secpay.com/starter/sm_solo.gif" alt="Solo" height="50" width="41"></div>';
}
?>
</div></center>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="style18" id="footer">
<?php echo $footer ?></div>
</body>
</html>
form.php contains

PHP Code:
<?php 

$billingfields 
'<form name="form1" method="post" action="'.$siteurl.'?act=billship2"><span style="font-size: 18px; color: #FF8000;">Billing Details</span>
<br>
<table width="500" height="416" border="0">
  <tr>
    <td> * Name: </td>
    <td><input type="text" name="bill_name" /></td>
  </tr>
  <tr>
    <td>* Company: </td>
    <td><input type="text" name="bill_company" /></td>
  </tr>
  <tr>
    <td>* Country: </td>
    <td><select name="bill_country">
      <option selected>- - Country - -</option>
      <option value="Albania">Albania</option>
    
 //  other countries would be here

    </select></td>
  </tr>
  <tr>
    <td>* Address Line 1: </td>
    <td><input type="text" name="bill_addr_1" /></td>
  </tr>
  <tr>
    <td>Address Line 2: </td>
    <td><input type="text" name="bill_addr_2" /></td>
  </tr>
  <tr>
    <td>* City: </td>
    <td><input type="text" name="bill_city" /></td>
  </tr>
  <tr>
    <td>* County / State / Province: </td>
    <td><input type="text" name="bill_state" /></td>
  </tr>
  <tr>
    <td>* Post / Zip Code: </td>
    <td><input type="text" name="bill_post_code" /></td>
  </tr>
  <tr>
    <td height="45">* Telephone: </td>
    <td><input type="text" name="bill_tel" /></td>
  </tr>
  <tr>
    <td height="40"><br />
* Email: </td>
    <td><input type="text" name="bill_email" /></td>
  </tr>
 
</table><br><br><input type="hidden" name="trans_id2" value="'
.$secrettransid.'">';






$shippingfields '<span style="font-size: 18px; color: #FF8000;">Shipping Details (Leave blank if same as Billing Details)</span><br><br>
<table width="500" height="416" border="0">
  <tr>
    <td> * Name: </td>
    <td><input type="text" name="ship_name" /></td>
  </tr>
  <tr>
    <td>* Company: </td>
    <td><input type="text" name="ship_company" /></td>
  </tr>
  <tr>
    <td>* Country: </td>
    <td><select name="ship_country">
      <option selected>- - Country - -</option>
      <option value="Albania">Albania</option>
      
// other countries here

    </select></td>
  </tr>
  <tr>
    <td>* Address Line 1: </td>
    <td><input type="text" name="ship_addr_1" /></td>
  </tr>
  <tr>
    <td>Address Line 2: </td>
    <td><input type="text" name="ship_addr_2" /></td>
  </tr>
  <tr>
    <td>* City: </td>
    <td><input type="text" name="ship_city" /></td>
  </tr>
  <tr>
    <td>* County / State / Province: </td>
    <td><input type="text" name="ship_state" /></td>
  </tr>
  <tr>
    <td>* Post / Zip Code: </td>
    <td><input type="text" name="ship_post_code" /></td>
  </tr>
  <tr>
    <td height="45">* Telephone: </td>
    <td><input type="text" name="ship_tel" /></td>
  </tr>
  <tr>
    <td height="40"><br />
* Email: </td>
    <td><input type="text" name="ship_email" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    
    <td><input type="submit" value="Proceed" /></td>
  </tr>
</table></form>'
;
Can someone help me display the prices on $action == billship2 ?
__________________

Please login or register to view this content. Registration is FREE

Last edited by Gilligan; 03-23-2008 at 07:57 PM..
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2008, 08:01 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
can anyone help me on this?
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-23-2008, 07:54 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Sorry, this is kinda urgent. The longer this takes the more money i'm losing.
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-23-2008, 10:40 PM Re: Form Help please!
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Could you just run a sql query by the transaction ID to get this info?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-23-2008, 11:46 PM Re: Form Help please!
Ultra Talker

Posts: 310
Trades: 0
Or you can use a session variable to store the order info using transaction id as the key when you have that information and then use it when you want to display it later.
dman_2007 is offline
Reply With Quote
View Public Profile
 
Old 03-24-2008, 07:58 AM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
i tried the sql query, but realized that billship2 hasn't received anything to do with the transaction id, nothing has been passed on to it.

As for session variables, I did think of this. But how would I implement this into my script?

Thanks for the replies by the way
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-25-2008, 05:28 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Anyone? Just to help me implement session variables to get the info across the billship2 ???
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-25-2008, 10:58 PM Re: Form Help please!
Ultra Talker

Posts: 310
Trades: 0
Use session_start() function at the top of the script to start the session and $SESSION array to store session variables.
dman_2007 is offline
Reply With Quote
View Public Profile
 
Old 03-26-2008, 01:18 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I'm really confused, the php tutorials out there don't seem to explain how to get the form from the 1st page, to the 3rd page.

Is it good to use cookies in this instance? But I understand some browsers block cookies.
__________________

Please login or register to view this content. Registration is FREE

Last edited by Gilligan; 03-26-2008 at 01:42 PM..
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-26-2008, 01:29 PM Re: Form Help please!
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
If you're not saving to a database, just pass the data through a hidden form field by echoing your information into it from page one in page two.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-26-2008, 01:45 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
For testing purposes I tried this.

1.php

PHP Code:
<form method="post" action="2.php">
  
  <
input type="text" name="name">
<
input type="submit" value="Submit">
</
form
2.php

PHP Code:
<?php 

session_start
();    // This connects to the existing session

$_SESSION['name'] = $_POST['name'];

echo 
'<a href="3.php">click here</a>';

?>
3.php

PHP Code:
<?php 

echo 'Name: ' $_SESSION['name'];

?>
This doesn't display anything, I just want to know how to use sessions to get from the first page, to the third page, regardless of what the user does in the second page.
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-26-2008, 01:54 PM Re: Form Help please!
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Try starting your session on page 3 as well.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-26-2008, 02:45 PM Re: Form Help please!
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
aaah.. thats done it
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Form Help please!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 3.07085 seconds with 12 queries