PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Why dont you just print_r($cart) and var_export($get_cart) like feyd said to be double sure? Could save a lot of time and keep some hairs on your head before you pull them out
I was mainly hoping that one of you may spot an error in the code shown. I guess the code must be fine, I'll try what you two suggested next. Thanks for the help guys!
$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracker
as tr left join inventory as inv on inv.id = tr.item_id where session_id = '$userses'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
print_r($get_cart_res);
var_export($get_cart_res);
And it returns:
"Resource id #3NULL"
I assume that means the query is returning data? So why won't it display?
$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracker
as tr left join inventory as inv on inv.id = tr.item_id where session_id = '$userses'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
while ($cart = mysql_fetch_array($get_cart_res)) {
print_r($cart);
var_export($cart);
}
And it returns a blank page. No errors...just nothing.
$cart = mysql_fetch_array($get_cart_res); //Doesn't contain any data since print_r is blank
Looks like $cart is empty. Tracking back your query probably returns nothing. Look through the mysql related parts of your code to see if you can spot where it'sa broken. I don't think it's the loop itself, it's what's going into the loop (nothing)
The code is correct, the query DOES pull data, but it won't display when I try to include it in the $message variable. It displays fine if I just echo the results...but not if it's mailed.
I've been searching everywhere for an answer to this problem but have not found one yet. Anybody have any guesses?
} else {
$get_cart = "select tr.id, inv.name, inv.price, tr.qty from tracking
as tr left join inventory as inv on inv.id = tr.item_id where session_id = '$userses'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
$subject = "blah blah blah...";
$message = "Dear $firstname $lastname,
Thank you for ordering at blah.com!
Order Summary:\n";
$message .= "************************";
while ($cart = mysql_fetch_array($get_cart_res)) {
$name = stripslashes($cart['name']);
$price = $cart['price'];
$qty = $cart['qty'];
$message .= "$qty";
}
$message .= "************************
Subtotal: $subtotal
Tax: $tax
Shipping: $shipping
Total: $total
Blah blah blah...";
mail($email, $subject, $message, "From: blah@blah.com\r\n");
header("Location: https://-URL-");
}
When the email comes through, the first part of the message is fine but the contents from the loop (now just quantity) does not appear, but the subtotal, tax, etc. DO appear. So what am I missing?