Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Php Array From Mysql Db


  • Please log in to reply
1 reply to this topic

#1 ohioman

ohioman

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:12:57 PM

Posted 05 May 2007 - 11:50 PM

Hi everyone! This is my first post. It has been a years since I've been back to PHP and mysql... so.. i'm very rusty and I'm hoping to advance my "re-learning curve" by posting here today. The deal is this... I am using the Idea cart 0.02 . I need to integrate with Paypal and I am running into problems with the population of the necessary submit form they require.

I am currently using: mysql_fetch_array to receive data... but it's just not right. If one item is added to the cart.. things are just fine.. it lists Item A, Quantity and Price and goes to checkout. BUT.. if I add a second item.. only Item A is submitted to Paypal... as if I never ordered Item B. I have done tests by the echo command of the particular row... and know that the contents I want are accessible and are a true mysql resource. There must be something incredibly stupid that I am missing or am more out of touch than I thought. :trumpet:

Please consider the following codes:

$result = mysql_db_query($dbname, "SELECT details.item, details.price, cart.cQuantity, details.special, details.serial FROM cart, details WHERE cart.pID = details.serial AND cart.id = ".$_SESSION[$site_session.'id']." AND details.pAvailable = 1 ORDER BY details.item");
$i=0;
$row = mysql_fetch_array($result);
($num_rows = mysql_num_rows($result));
for($i=0; $i < $num_rows; $i++){
$myitem[$i] = $row['item'];
$sprice[$i] = $row['price'];
$cQuantity[$i] = $row['cQuantity'];
if($row['special'] == 1) {
$result_special = mysql_db_query($dbname, "SELECT item, price FROM specials WHERE serial = ".$row["serial"]);
$row_special = mysql_fetch_array($result_special);
$myitem[$i] = $row_special['item'];
$sprice[$i] = $row_special['price'];
++$i;
}
}

This is to retrieve the values from the database... so that i can then echo their values in the submit form that Paypal requires with their values.

Here is good ol' Paypal's form to be populated:

<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="myemail@service.com">
<!-- Begin First Item -->

<input type="hidden" name="quantity_1" value="<?php echo$cQuantity[1]; ?>">

<input type="hidden" name="item_name_1" value="<?php echo$myitem[1]; ?>">
<input type="hidden" name="item_number_1" value="">
<input type="hidden" name="amount_1" value="<?php echo$sprice[1]; ?>">

<input type="hidden" name="shipping_1" value="0.01">
<input type="hidden" name="shipping2_1" value="0.01">
<input type="hidden" name="handling_1" value="0.01">
<input type="hidden" name="tax_1" value="0.01">
<input type="hidden" name="on0_1" value="Option Name1 A">
<input type="hidden" name="os0_1" value="Option Selection1 A">
<input type="hidden" name="on1_1" value="Option Name2 A">
<input type="hidden" name="os1_1" value="Option Selection2 A">
<!-- End First Item -->

<!-- Begin Second Item -->

<input type="hidden" name="quantity_2" value="<?php echo$cQuantity[2]; ?>">

<input type="hidden" name="item_name_2" value="<?php echo$myitem[2]; ?>">
<input type="hidden" name="item_number_2" value="">
<input type="hidden" name="amount_2" value="<?php echo$sprice[2]; ?>">

<input type="hidden" name="shipping_2" value="0.01">
<input type="hidden" name="shipping2_2" value="0.01">
<input type="hidden" name="handling_2" value="0.01">
<input type="hidden" name="tax_2" value="0.01">
<input type="hidden" name="on0_2" value="Option Name1 A">
<input type="hidden" name="os0_2" value="Option Name2 A">
<input type="hidden" name="on1_2" value="Option Name2 A">
<input type="hidden" name="os1_2" value="Option Selection2 A">
<!-- End Second Item -->

When I run it and view the source... this is what the above form generated:

<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="myemail@service.com">
<!-- Begin First Item -->

<input type="hidden" name="quantity_1" value="1">

<input type="hidden" name="item_name_1" value="Ohiomans Product A">
<input type="hidden" name="item_number_1" value="">
<input type="hidden" name="amount_1" value="9.95">

<input type="hidden" name="shipping_1" value="0.01">
<input type="hidden" name="shipping2_1" value="0.01">
<input type="hidden" name="handling_1" value="0.01">
<input type="hidden" name="tax_1" value="0.01">
<input type="hidden" name="on0_1" value="Option Name1 A">
<input type="hidden" name="os0_1" value="Option Selection1 A">
<input type="hidden" name="on1_1" value="Option Name2 A">
<input type="hidden" name="os1_1" value="Option Selection2 A">
<!-- End First Item -->

<!-- Begin Second Item -->

<input type="hidden" name="quantity_2" value="">

<input type="hidden" name="item_name_2" value="">
<input type="hidden" name="item_number_2" value="">
<input type="hidden" name="amount_2" value="">

<input type="hidden" name="shipping_2" value="0.01">
<input type="hidden" name="shipping2_2" value="0.01">
<input type="hidden" name="handling_2" value="0.01">
<input type="hidden" name="tax_2" value="0.01">
<input type="hidden" name="on0_2" value="Option Name1 A">
<input type="hidden" name="os0_2" value="Option Name2 A">
<input type="hidden" name="on1_2" value="Option Name2 A">
<input type="hidden" name="os1_2" value="Option Selection2 A">
<!-- End Second Item -->

See.. second item.. no value. :flowers:

I would appreciate sample coding to look at or suggestions. :thumbsup: I know that Paypal has a forum... but... most of the help there is deals with the submit form ==> foward.. not backwards to the webmaster. :inlove:

Thank you much,

Calvin

P.S. As the coding will suggest.. I am only interested in the quantity, item name and price.

BC AdBot (Login to Remove)

 


m

#2 ohioman

ohioman
  • Topic Starter

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:12:57 PM

Posted 07 May 2007 - 01:58 AM

This problem has been solved. To help others, I thought I would post the code that fixes the issue of populating the Paypal form in PHP:

$itemquantity = array();
$itemname = array();
$itemprice = array();
$result = mysql_db_query($dbname, "SELECT details.item, details.price, cart.cQuantity, details.special, details.serial FROM cart, details WHERE cart.pID = details.serial AND cart.id = ".$_SESSION[$site_session.'id']." AND details.pAvailable = 1 ORDER BY details.item");
$a=mysql_num_rows($result);
if ($a>0) {
for ($i=0;$i < $a;$i++) {

array_push($itemquantity,mysql_result($result,$i,"cQuantity"));
array_push($itemname,mysql_result($result,$i,"item"));
array_push($itemprice,mysql_result($result,$i,"price"));
$count++;
}
}

Once you add that code... simply change the select query to suit your database needs. You can then have the Paypal form coded this way:

<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="myemail@myservice.com">
<!-- Begin First Item -->

<input type="hidden" name="quantity_1" value="<?php echo$itemquantity[0]; ?>">

<input type="hidden" name="item_name_1" value="<?php echo$itemname[0]; ?>">
<input type="hidden" name="item_number_1" value="">
<input type="hidden" name="amount_1" value="<?php echo$itemprice[0]; ?>">

<input type="hidden" name="shipping_1" value="0.01">
<input type="hidden" name="shipping2_1" value="0.01">
<input type="hidden" name="handling_1" value="0.01">
<input type="hidden" name="tax_1" value="0.01">
<input type="hidden" name="on0_1" value="Option Name1 A">
<input type="hidden" name="os0_1" value="Option Selection1 A">
<input type="hidden" name="on1_1" value="Option Name2 A">
<input type="hidden" name="os1_1" value="Option Selection2 A">
<!-- End First Item -->

<!-- Begin Second Item -->

<input type="hidden" name="quantity_2" value="<?php echo$itemquantity[1]; ?>">

<input type="hidden" name="item_name_2" value="<?php echo$itemname[1]; ?>">
<input type="hidden" name="item_number_2" value="">
<input type="hidden" name="amount_2" value="<?php echo$itemprice[1]; ?>">

<input type="hidden" name="shipping_2" value="0.01">
<input type="hidden" name="shipping2_2" value="0.01">
<input type="hidden" name="handling_2" value="0.01">
<input type="hidden" name="tax_2" value="0.01">
<input type="hidden" name="on0_2" value="Option Name1 A">
<input type="hidden" name="os0_2" value="Option Name2 A">
<input type="hidden" name="on1_2" value="Option Name2 A">
<input type="hidden" name="os1_2" value="Option Selection2 A">
<!-- End Second Item -->

<!-- Begin Third Item -->

<input type="hidden" name="quantity_2" value="<?php echo$itemquantity[2]; ?>">

<input type="hidden" name="item_name_2" value="<?php echo$itemname[2]; ?>">
<input type="hidden" name="item_number_2" value="">
<input type="hidden" name="amount_2" value="<?php echo$itemprice[2]; ?>">

<input type="hidden" name="shipping_2" value="0.01">
<input type="hidden" name="shipping2_2" value="0.01">
<input type="hidden" name="handling_2" value="0.01">
<input type="hidden" name="tax_2" value="0.01">
<input type="hidden" name="on0_2" value="Option Name1 A">
<input type="hidden" name="os0_2" value="Option Name2 A">
<input type="hidden" name="on1_2" value="Option Name2 A">
<input type="hidden" name="os1_2" value="Option Selection2 A">
<!-- End Third Item -->

<input type="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" border="0" value="Submit" alt="Make your payments with PayPal. It is free, secure, effective.">
</form>

In this example, I am just using the basics. You can use this technique for all the fields of the form if you want to. There might be other ways of doing this.. but.. I know this one works for really any cart that is out there that uses PHP.

I hope this posting helps someone out there that needs it.

Thank you!

Calvin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users