kpetsche20 Posted June 15, 2008 Share Posted June 15, 2008 Hello, I'm trying to make a shopping cart system where a persons adds a bunch of products to their cart and when they can to checkout the info is deleted from the database and then is sent in an email. Right now it only sends 1 value in the email, regardless of how many products a person has in a table. Here is a snippet of the mail code <?php if(isset($_POST['submit'])) { ///GET EMAIL $sh = "SELECT * FROM users WHERE login = 'admin'"; $sh2 = mysql_query($sh); $sql = "SELECT * FROM checkout WHERE username = '".$_SESSION['id']."'"; $run = mysql_query($sql); for($x=0; $x < mysql_num_rows($run); $x++) { $data = mysql_fetch_array($run); $data2 = mysql_fetch_array($sh2); $body .= " Name: ".$data['name']." QTY: ".$data['qty']." "; $to = $data2['email']; mail($to, 'Subject', $body) or die(mysql_error()); echo "Quote Sent Successfully"; $delete = "DELETE FROM checkout WHERE username = '".$_SESSION['id']."'"; mysql_query($delete) or die(mysql_error); } } else { ?> Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 15, 2008 Share Posted June 15, 2008 <?php if(isset($_POST['submit'])) { ///GET EMAIL $sh = "SELECT * FROM users WHERE login = 'admin'"; $sh2 = mysql_query($sh); $body=""; $sql = "SELECT * FROM checkout WHERE username = '".$_SESSION['id']."'"; $run = mysql_query($sql); $data2 = mysql_fetch_array($sh2); $to = $data2['email']; while ($_rows=mysql_fetch_array($_run)) { $body .= " Name: ".$data['name']." QTY: ".$data['qty']." "; } mail($to, 'Subject', $body) or die(mysql_error()); echo "Quote Sent Successfully"; $delete = "DELETE FROM checkout WHERE username = '".$_SESSION['id']."'"; mysql_query($delete) or die(mysql_error); } ?> Maybe this will work? Btw, I don't know why you have "or die(mysql_error);" next to the mail function, because I don't think it would cause a mysql error even if it had an error. D: Quote Link to comment Share on other sites More sharing options...
kpetsche20 Posted June 15, 2008 Author Share Posted June 15, 2008 It sends an email, but if there is more than 1 value in the database it only send 1, I need it to send all Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 15, 2008 Share Posted June 15, 2008 I edited my post, try that again. Lmfao sorry I'm kinda tired right now. Forgot toedit the variables. Try this: <?php if(isset($_POST['submit'])) { ///GET EMAIL $sh = "SELECT * FROM users WHERE login = 'admin'"; $sh2 = mysql_query($sh); $body=""; $sql = "SELECT * FROM checkout WHERE username = '".$_SESSION['id']."'"; $run = mysql_query($sql); $data2 = mysql_fetch_array($sh2); $to = $data2['email']; while ($_rows=mysql_fetch_array($run)) { $body .= " Name: ".$_rows['name']." QTY: ".$_rows['qty']." "; } mail($to, 'Subject', $body) or die(mysql_error()); echo "Quote Sent Successfully"; $delete = "DELETE FROM checkout WHERE username = '".$_SESSION['id']."'"; mysql_query($delete) or die(mysql_error); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.