Debt Consolidation - Loans - Free Ringtone - Free Ringtone - Mobile Phones

PDA

View Full Version : Help me please! PHP/MySQL problem again!


cowguru2000
Mar 5th 2007, 3:07 pm
I have this email program, and I don't know what's wrong with it! This is the email I got:

(subject: Your order number -- JoGrammah.com)


Thank you for ordering at JoGrammah.com!

You ordered 2 item(s).
Your order costs $6.7.
You ordered:

Item number : Item name: qty:


Your order will be shipped to:

Bob Schmoe
123 Fake St.
Woodbridge, AL
12345

Since our store is not fully completed, you may be contacted at 123-456-7890 for further details concerning your order.

Sincerely,
-JoGrammah.com staff


It won't show me what items I actually ordered, and the order number that was in the subject just disappeared! (the subject was supposed to be like this: "Your order number x -- JoGrammah.com". The "x" is their order number.)

Here's my PHP:

<?php
/* File: email.inc
* Desc: Emails the shopper and orders@jogrammah.com.
*/

$connect = connect_to_db("Vars.inc");

$query = 'SELECT * FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '"';

$result = mysql_query($query)
or die("sql_email: ".mysql_error());

$numrows = mysql_num_rows($result);

if ($numrows) {
$itemsmessage = "You ordered:\n\n";
while ($row = mysql_fetch_assoc($result)) {

$_SESSION['order_number'] = $ordernumber;

$query = 'SELECT name FROM Food WHERE catalog_number = (SELECT catalog_number FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '")';

$result = mysql_query($query)
or die("sql_email2: ".mysql_error());

while ($row = mysql_fetch_array($result)){
$blah = $row['name'];
echo $row['name'];
echo "<br>";
}

$itemsmessage = $itemsmessage . "Item number " . $row['item_number'] . ":" . " Item name: " . $blah . " qty: " . $row['quantity'] . "\n";
}
};

$emailto = $_SESSION['email'];
$orderID = $_SESSION['order_number'];
$subject = "Your order number ".$_SESSION['order_number']." -- JoGrammah.com";
$from = "From: orders@jogrammah.com";
$from2 = "From: ".$emailto;

$ship_name = $_SESSION['ship_name'];
$ship_street = $_SESSION['ship_street'];
$ship_city = $_SESSION['ship_city'];
$state = $_SESSION['ship_state'];
$ship_zip = $_SESSION['ship_zip'];
$phone = $_SESSION['phone'];
$cc_number = $_SESSION['cc_number'];
$ordertotal = $_SESSION['order_total'];
$noitemsordered = $_SESSION['n_items'];

$subject2 = "Order # ".$_SESSION['order_number'].": ".$_SESSION['ship_name'];

$message = "Thank you for ordering at sJoGrammah.com!\n
You ordered $noitemsordered item(s).
Your order costs "."$"."$ordertotal.
$itemsmessage
\nYour order will be shipped to:\n\n$ship_name\n$ship_street\n$ship_city, $state\n$ship_zip\n\nSince our store is not fully completed, you may be contacted at $phone for further details concerning your order.\n\nSincerely,\n-JoGrammah.com staff";


$message2 = "ORDER NUMBER $orderID \n\nShip to:\n$ship_name\n$ship_street\n$ship_city, $ship_state\n\nPhone number: $phone\nEmail: $emailto";

mail($emailto, $subject, $message, $from);

mail("orders@jogrammah.com", $subject2, $message2, $from2);

?>

PhatDV
Mar 5th 2007, 5:10 pm
This:

while ($row = mysql_fetch_array($result)) {
$blah = $row['name'];
echo $row['name'];
echo "<br>";
}

is overwriting your $row variable. Just change $row here to something else and that should get it working.

ccharp
Mar 6th 2007, 2:27 am
sigh I;ve done the same thing before and had trouble spotting it...nice catch PhatDV

cowguru2000
Mar 6th 2007, 12:55 pm
Thank you so much!

You were probably right, but I spotted another error: when I wrote $_SESSION['order_number'] = $ordernumber, I meant the other way around. BIG WHOOPS! :-)

Kalyse
Mar 6th 2007, 1:03 pm
Ive done that many many times too.

Where I have sub queries inside a loop

cowguru2000
Mar 6th 2007, 1:36 pm
Speaking of subqueries, it gave me a "more than 1 row in subquery" error, but I figured it out...slightly. Please refer to my newest thread about that!

cowguru2000
Mar 6th 2007, 5:11 pm
Wow! Well, I've got to say, everybody in this forum helped me and I've come a loooooong way with PHP, MySQL, and my email program.

Now, I set up this realllllly confusing loop that actually got my email program to work!... most of the way.

Before I say anything else, here's my PHP code:

php Code:
<?php
/* File: email.inc
* Desc: Emails the shopper and orders@jogrammah.com.
*/

$connect = connect_to_db("Vars.inc");

$query = 'SELECT * FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '"';

$result = mysql_query($query)
or die("sql_email: ".mysql_error());

$numrows = mysql_num_rows($result);

$ordernumber = $_SESSION['order_number'];

if ($numrows) {
$itemsmessage = "You ordered:\n\n";
while ($row = mysql_fetch_assoc($result)) {

$query2 = 'SELECT catalog_number FROM order_item WHERE order_number = "' . mysql_real_escape_string($_SESSION['order_number']) . '"';

$result2 = mysql_query($query2)
or die ("sql_email2: ".mysql_error());

while ($rows2 = mysql_fetch_assoc($result2)) {

$query3 = 'SELECT name FROM Food WHERE catalog_number = "' . $rows2['catalog_number'] . '"';

$result3 = mysql_query($query3)
or die("sql_email3: ".mysql_error());

while ($rw = mysql_fetch_array($result3)) {
$blah = $rw['name'];
/* echo $rw['name'];
echo "<br>"; */
}
}

$itemsmessage = $itemsmessage . "Item number " . $row['item_number'] . ":" . " Item name: '" . $blah . "' | qty: " . $row['quantity'] . "\n";
}
};

$emailto = $_SESSION['email'];
$orderID = $_SESSION['order_number'];
$subject = "Your order number ".$_SESSION['order_number']." -- JoGrammah.com";
$from = "From: orders@jogrammah.com";
$from2 = "From: ".$emailto;

$ship_name = $_SESSION['ship_name'];
$ship_street = $_SESSION['ship_street'];
$ship_city = $_SESSION['ship_city'];
$state = $_SESSION['ship_state'];
$ship_zip = $_SESSION['ship_zip'];
$phone = $_SESSION['phone'];
$cc_number = $_SESSION['cc_number'];
$ordertotal = $_SESSION['order_total'];
$noitemsordered = $_SESSION['n_items'];

$subject2 = "Order # ".$_SESSION['order_number'].": ".$_SESSION['ship_name'];

$message = "Thank you for ordering at JoGrammah.com!\n
You ordered $noitemsordered item(s).
Your order costs "."$"."$ordertotal.
$itemsmessage
\nYour order will be shipped to:\n\n$ship_name\n$ship_street\n$ship_city, $state\n$ship_zip\n\nSince our store is not fully completed, you may be contacted at $phone for further details concerning your order.\n\nSincerely,\n-JoGrammah.com staff";


$message2 = "ORDER NUMBER $orderID \n\nShip to:\n$ship_name\n$ship_street\n$ship_city, $ship_state\n\nPhone number: $phone\nEmail: $emailto";

mail($emailto, $subject, $message, $from);

mail("orders@jogrammah.com", $subject2, $message2, $from2);

?>
Now, there's a slight problem. Look at the email it sent me.

Code:
Thank you for ordering at JoGrammah.com!

You ordered 4 item(s).
Your order costs $21.2.
You ordered:

Item number 1: Item name: 'Peppermint Swirl' | qty: 1.00
Item number 2: Item name: 'Peppermint Swirl' | qty: 2.00
Item number 3: Item name: 'Peppermint Swirl' | qty: 3.00
Item number 4: Item name: 'Peppermint Swirl' | qty: 4.00


Your order will be shipped to:

Bob Schmoe
123 Fake St.
Somewhere, AL
12345

Since our store is not fully completed, you may be contacted at 123-456-7890 for further details concerning your order.

Sincerely,
-JoGrammah.com staff
Now, this is excellent!...except for the fact that I didn't order a total of 10 'Peppermint Swirls'. Everything's right, except it just keeps repeating the 'Peppermint Swirl', which is only the first item I "bought"!

This is the last thing I want to do with my email program. It would be SO AWESOME if someone could PLEASE help me!

TIA,
-Joe