Page 1 of 1

[SOLVED] php help needed with code

Posted: Mon Jul 12, 2010 6:20 am
by Bunter
Hi,

I have an issue and being a newbe I was hoping that somebody here could help / point me in the right direction. The issue I am having is passing a PHP var into a form value for posting over to WorldPay.

I have coded a cart using ajax / php, once the customer clicks checkout they are taken to a order page (for entry of payment details to pass to worldpay). I have the customers items and total passed to this page via a var that is posted.

I need to know how to make the items into a string (seperated via a comma) and then passed into a var that I can submit with the form to worldpay. I am also having the same issue with the total amount.

The code I have is the following:

Code: Select all

<?php

define('INCLUDE_CHECK',1);
require "connect.php";

if(!$_POST)
{
	if($_SERVER['HTTP_REFERER'])
	header('Location : '.$_SERVER['HTTP_REFERER']);
	
	exit;
}

?>
Which of of course is used to bring var's accross from cart....


The following code is how I display the ordered items and value

Code: Select all

<?php
				
				$cnt = array();
				$products = array();
				
				
				foreach($_POST as $key=>$value)
				{
					$key=(int)str_replace('_cnt','',$key);
				
					$products[]=$key;
					$cnt[$key]=$value;
				}

				$result = mysql_query("SELECT * FROM internet_shop WHERE id IN(".join($products,',').")");
				
				if(!mysql_num_rows($result))
				{
					echo '<p><strong>There was an error with your order!</strong></p>';
				}
				else
				{
					echo '<p><strong>Your order:</strong></p>';
					
					while($row=mysql_fetch_assoc($result))
					{
						echo '<h4>'.$cnt[$row['id']].' x '.$row['name'].' - '.$row['description'].'</h4>';
						
						
						$total+=$cnt[$row['id']]*$row['price'];
						$total = number_format($total, 2, '.', '');
						
					}
		
					echo '<br /><p><strong>Total: &pound;'.$total.' inc VAT</strong></p>';
				}
				?>

The form I have is:

Code: Select all

<form id="purchase" name="purchase" action="https://secure-test.wp3.rbsworldpay.com/wcc/purchase" method="post" >
						    <fieldset>
                              <input type="hidden" name="testMode" value="100">
                              <input type="hidden" name="instId" value="XXXXX">
							  <input type="hidden" name="cartId" value="Retail Sale">
							  <input type="hidden" name="currency" value="GBP">
                              <input type="hidden" name="desc" value="">
							  <input type="hidden" name="amount" value="">
							  <input type=hidden name="accId1" value="XXXXX"> 
							  <label for="name" id="name_label">Name</label><br />
							  <input type="text" name="name" id="name" size="30" value="" class="text-input" />
							  <br style="clear:both" />
                              <label for="address" id="address_label">Address</label><br />
							  <input type="text" name="address" id="address" size="30" value="" class="text-input" />
                              <br style="clear:both" />
                              <label for="postcode" id="postcode_label">Postcode</label><br />
							  <input type="text" name="postcode" id="postcode" size="30" value="" class="text-input" />
                              <br style="clear:both" />
                              <label for="tel" id="tel">Telephone</label><br />
							  <input type="text" name="tel" id="tel" size="30" value="" class="text-input" />
                              <br style="clear:both" />
							  <label for="email" id="email_label">Email</label><br />
							  <input type="text" name="email" id="email" size="30" value="" class="text-input" />
							  <br />
							  <input type="submit" name="submit" class="but" id="submit_btn" value="Buy Now"/>
							</fieldset>
                          </form>
I need to pass the total value ($total) into the form field value for "amount" and the items as a single line seperated by a comma into the form field of "desc"

I have tried various ways, such as passing the php var into a javascript var at end of page, then using (document.purchase.amount.value = javaVar), however I seem to be having a major issue in getting it to work. I would really be thankful of any help offered.

Thanks

Re: PHP Form / Worldpay

Posted: Mon Jul 12, 2010 10:55 am
by Bunter
****BUMP****

If anybody could help with this it would be of a great help

Thanks

Re: [SOLVED] php help needed with code

Posted: Tue Jul 13, 2010 5:26 am
by Bunter
I have resolved this now anyway.... Thanks to anybody that looked at this, however I did imagine that as a newbie this forum would be filled with people holding more knowledge and understanding than I do.

Thanks

Re: [SOLVED] php help needed with code

Posted: Tue Jul 13, 2010 8:42 am
by Jade
Talk about having a stick up the wrong place... just because you don't get an answer within what, 24 hours of your post, doesn't mean you have to be nasty about it.

Re: [SOLVED] php help needed with code

Posted: Tue Jul 13, 2010 8:48 am
by Bunter
Hi,
Jade wrote:Talk about having a stick up the wrong place... just because you don't get an answer within what, 24 hours of your post, doesn't mean you have to be nasty about it.
Jade, with regards to your comment, if you feel that comment is nasty then maybe it says more about your character than about mine. That comment is not nasty, it’s just an expression of how I thought I might of received an answer from people who looked at it.

My apologies if you feel that is nasty, however I believe that your taking this personally as I did pm you asking for help and you of course did not, even reply.

To everybody who reads this, if you feel that comment is "nasty", then my apologies.

Thanks,

Re: [SOLVED] php help needed with code

Posted: Tue Jul 13, 2010 8:53 am
by Jade
Unfortunately it sounds like for you "Instant gratification is not soon enough." -- Meryl Streep

Excuse me for not dropping everything and doing your work just because you sent a private message asking for help.

Re: [SOLVED] php help needed with code

Posted: Tue Jul 13, 2010 9:15 am
by Bunter
Jade wrote:Unfortunately it sounds like for you "Instant gratification is not soon enough." -- Meryl Streep

Excuse me for not dropping everything and doing your work just because you sent a private message asking for help.
This is becoming very stupid....

I have now turned off auto notification of a response, as I do not have time for this.... It would appear that you sit on this forum looking for grief or easy problems to solve.

I only pm'd you as you were online and had been answering a load of posts / querries... I am sorry that I thought you may be able to help, or at least of been some assistance!!!

Contiune to reply as much as you wish, and the use of "quotes" just demostrates you incapacicity to deliver a line that is relivant! Also that line would highlight the fact that one is busy and has a timeline to meet, I am sorry that I can not sit on this forum all day and have a banter with you, maybe you should get some work in and keep yourself busy. (I am sure you can find somebody else to harrass... If you ask nicely you might make your first friend!)

Thats my final word!

Again sorry to everybody else reading this, however as you can see this "Jade" has taken it upon herself to start grief within a community forum where one was looking for help. For future reference I would strongly recommend that nobody PM's Jade for assistance.