Page 1 of 1

Problem getting price from mySql db using php codes???

Posted: Tue Jun 03, 2008 7:15 am
by ashebrian
Ok what i did was i'm able to get the amountby using $_POST. But it was displayed with a comma so i used

Code: Select all

str_replace
to get rid of this. However, the 3rd party(transaction company who has a secure webpage for credit card validation) still does not see that as cents which is needed and will not accept it. I think that they'll still read it as a comma.

Therefore, i think posting the prices over will not work. I'm going back to get the info from the db again. This time i'm trying to add the od_price_total to my tbl_order table. The only thing i've changed in my checkout-functions.php is from this code that used post and has the correct amount but wouldn't send due to the str_replace:

Code: Select all

$orderTotal = str_replace(',', '', $_POST['totalTotal']);
 
echo "orderTotal= $orderTotal";
return $orderTotal;
and replaced it with this:

Code: Select all

 
$orderTotal = 0;
$totalTotal    = $_POST['totalTotal'];
    
    $sql = "SELECT SUM('$totalTotal')
            FROM tbl_order
            WHERE od_id = $orderId";
    $result = dbQuery($sql);
 
    if (dbNumRows($result) == 1) {
        $row = dbFetchRow($result);
        $totalPurchase = $row[0];
        
        $orderTotal = $totalPurchase;
        echo "orderTotal= $orderTotal";
    }   
    return $orderTotal;


however, this code i replace it with only returns 2 from the db. ummmmmmm.....My table is as follows:

Code: Select all

CREATE TABLE `tbl_order` (
  `od_id` int(10) unsigned NOT NULL auto_increment,
  `member_username` varchar(30),
  `od_date` datetime default NULL,
  `od_last_update` datetime NOT NULL default '0000-00-00 00:00:00',
  `od_status` enum('New', 'Paid', 'Shipped','Completed','Cancelled') NOT NULL default 'New',
  `od_memo` varchar(255) NOT NULL default '',
  `od_shipping_first_name` varchar(50) NOT NULL default '',
  `od_shipping_last_name` varchar(50) NOT NULL default '',
  `od_shipping_address1` varchar(100) NOT NULL default '',
  `od_shipping_address2` varchar(100) NOT NULL default '',
  `od_shipping_phone` varchar(32) NOT NULL default '',
  `od_shipping_city` varchar(100) NOT NULL default '',
  `od_shipping_state` varchar(32) NOT NULL default '',
  `od_shipping_postal_code` varchar(10) NOT NULL default '',
  `od_shipping_cost` decimal(5,2) default '0.00',
  `od_vat` int(2) NOT NULL default '21',
  `od_price_total` bigint NOT NULL default '',
  `od_payment_first_name` varchar(50) NOT NULL default '',
  `od_payment_last_name` varchar(50) NOT NULL default '',
  `od_payment_address1` varchar(100) NOT NULL default '',
  `od_payment_address2` varchar(100) NOT NULL default '',
  `od_payment_phone` varchar(32) NOT NULL default '',
  `od_payment_city` varchar(100) NOT NULL default '',
  `od_payment_state` varchar(32) NOT NULL default '',
  `od_payment_postal_code` varchar(10) NOT NULL default '',
  PRIMARY KEY  (`od_id`,`member_username`)
) TYPE=MyISAM AUTO_INCREMENT=1610 ;
I'm not sure if bigint is a problem for od_price_total. I can post the full code here if needed to. Please help.

Re: Problem getting price from mySql db using php codes???

Posted: Tue Jun 03, 2008 7:42 am
by vargadanis
Hi!

If you use str_replace it would do it unless the problem is somewhere else. Did you try to debug the code and see what errors you get? That would help us...

Re: Problem getting price from mySql db using php codes???

Posted: Tue Jun 03, 2008 1:52 pm
by ashebrian
I have been debugging using echo on each page.

1) what i'm doing is after the customer edits their details for shipping.
2) its displayed to them again on the next page and assigned the prices in the background are also posted from the shipping script in a hidden input.
3) The next script is like a process that is automatically read away from the customers eyes
4) and is sent to the final page before the 3rd parties page.

The echo has worked fine with no decimal point or commas in the script in my point 2 above. But when go to point 4 where the echo from point 3 is the same value but with a comma so i had to make changes by adding the

Code: Select all

str_replace
Here it sorted it but wouldn't be sent to the 3rd party as it gave me an error as invalid amount assigned.

Therefore, i've gone back to my old configuration and using the db but can't get the values to be added to the db as when i look at them they are assigned '0'. Also when i echo from the db its the same value of '0'.