Changing a status of an order


#1

Hi,

I am new to php, but slowly getting to grips with it, I am making an online ordering system. Most of it is working apart from a function which updates the status of a Paypal order once an order has been processed.

[php]
//Checks when an orders complete, if paid via paypal, it will display in the admin section that the order is ‘PAID’
if ($sql = “SELECT od_payment_method
FROM tbl_order
WHERE od_payment_method = ‘paypal’”) {
$sql = “UPDATE tbl_order
SET od_status = ‘Paid’”;}
[/php]

This doesn’t seem to work, please can someone put me in the right direction?

Thanks


#2

Your using two different SQL commands without processing either. Setting up a SQL query is step 1, then you have to query it, step 2 and then handle the second query, step 3. It should be more like this sample layout… (Untested, just sample code, but, should work…)

$sql = “SELECT od_payment_method FROM tbl_order WHERE od_payment_method = ‘paypal’”;
$results = mysql_query($sql) or mysql_error();
if($results) {
$sql = “UPDATE tbl_order SET od_status = ‘Paid’ WHERE od_payment_method = ‘paypal’”;
$results = mysql_query($sql) or mysql_error();
}

But, of course, for some reason you do not have any mention in the tbl_order WHERE statement for the order you are working with such as the paypal ID for that client. So, I think you will have a problem with this code anyways. I suggest looking at the first part of this code and figure out how to identify a unique payment ID from the orders. What you are showing is just getting all orders from paypal and marking them paid. That will not be safe and most likely will mark unpaid ones paid. Hope that made sense! Good luck…


#3

Thanks, this helped to get it working! ;D