oneski Posted March 27, 2008 Share Posted March 27, 2008 i have very basic php skills. Im using wamp server to run mysql through php. I have argosoft mail server running with outlook to recieve emails send from my local host. This all works fine. What im trying to do is get automatic email to respond once a users has selected an item to order. The email needs to contain data from 2 seperate tables in mysql , these being users and stock. this is the code i have so far.. order.php (this so far selects the stock data into a pull down box and lets the user add the amount wanted.) I want it to display the data of the product when an item is selected from the pull down box. <?php session_start(); include("header.php"); echo "<form action='process.php' method='post'>"; echo "<form action='messageUser.php' method='post'>"; echo "Select stock:<br>"; if(!isset($_GET['to'])) { $query = "SELECT * FROM stock"; } $con = makeConn(); $resultUsers = mysql_query($query); if (mysql_num_rows($resultUsers) > 0){ echo "<select name='stock'>"; while ($row = mysql_fetch_array($resultUsers)){ echo "<option value='" . $row['stockID'] . "'>" . $row['name'] . "</option>\n"; } echo "</select>"; }else{ echo msgError("Error: Your message was not sent."); } echo "Quantity: <input name='quantity' type='text' />"; echo "<input type='submit' />"; echo "</form>"; include("footer.php"); ?> This then send to process.php which automatically send an email to both the user and the webserver host. The problem is i want the email to contain both the ordered data and the users data if that is possible. The the moment it has all the users data but only the amount ordered and the stockID of the stocks data. process.php <?php session_start(); include("header.php"); if(isset($_SESSION['id'])){ $quantity = $_POST['quantity']; $item = $_POST['stock']; echo "You have ordered ". $quantity . " " . $item . ".<br />"; $to ="" . $_SESSION['email'] . ", "; $to .= "pj@localhost"; //Select users information $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("PJindustrial", $con); $result = mysql_query("SELECT * FROM users WHERE userID = " . $_SESSION['id'] . ""); while($row = mysql_fetch_array($result)) { // Your subject $subject="PJ Industrial Invoice"; // From $header="from: PJ Industrial Invoice <[email protected]>"; // Your message $message="Order Confirmation\r\n"; $message.="This is to confirm the order of:\r\n"; $message.="\r\n"; $message.="\r\n"; $message.="Quantity: ". $quantity . "\r\n"; $message.="Item: ". $item . "\r\n"; $message.="\r\n"; $message.="\r\n"; $message.="The address that this item will be invoiced to is as follows:\r\n"; $message.="\r\n"; $message.="\r\n"; $message.="" . $row['forename'] . " " . $row['surname'] . ".\r\n"; $message.="" . $row['fullAddress'] . ".\r\n"; $message.="" . $row['postCode'] . ".\r\n"; $message.="\r\n"; $message.="\r\n"; $message.="If there are any concerns regarding this item please contact an admin via the messaging system on the control panel or view the other contact details on the contact us page.\r\n"; } mysql_close($con); // send email $sentmail = mail($to,$subject,$message,$header); // if your email succesfully sent if($sentmail){ echo "A confirmation email of your order has been sent to your email account."; echo "The page will refresh to your control panel in 15 seconds.<br> If you do not with to wait please click <a href='control.php'>here</a>"; echo "<meta http-equiv='refresh' content='15;URL=control.php'>"; } else { echo "Cannot Send Email "; } } include("footer.php");?> These are my sql dumps: -- phpMyAdmin SQL Dump -- version 2.10.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Mar 27, 2008 at 06:42 PM -- Server version: 5.0.45 -- PHP Version: 5.2.5 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `pjindustrial` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE `users` ( `userID` int(10) NOT NULL auto_increment, `userName` varchar(20) NOT NULL, `forename` varchar(20) NOT NULL, `surname` varchar(20) NOT NULL, `company` varchar(50) NOT NULL, `fullAddress` varchar(70) NOT NULL, `postCode` varchar( NOT NULL, `password` varchar(10) NOT NULL, `email` varchar(40) NOT NULL, `isAdmin` tinyint(1) NOT NULL, PRIMARY KEY (`userID`), UNIQUE KEY `userID` (`userID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ; SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `pjindustrial` -- -- -------------------------------------------------------- -- -- Table structure for table `stock` -- CREATE TABLE `stock` ( `stockID` int(10) NOT NULL auto_increment, `size` int(20) NOT NULL, `name` varchar(20) NOT NULL, `amountInStock` int(200) NOT NULL, `pricePerItemS` varchar(200) NOT NULL, `pricePerItemB` varchar(200) NOT NULL, `reorderLevel` int(50) NOT NULL, `description` varchar(100) NOT NULL, PRIMARY KEY (`stockID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ; Link to comment https://forums.phpfreaks.com/topic/98203-php-email-help/ Share on other sites More sharing options...
oneski Posted March 28, 2008 Author Share Posted March 28, 2008 would really appreciate help, thanks Link to comment https://forums.phpfreaks.com/topic/98203-php-email-help/#findComment-503028 Share on other sites More sharing options...
conker87 Posted March 28, 2008 Share Posted March 28, 2008 Why have you got two <form> tags? Link to comment https://forums.phpfreaks.com/topic/98203-php-email-help/#findComment-503032 Share on other sites More sharing options...
oneski Posted March 28, 2008 Author Share Posted March 28, 2008 ah id been doing some editing of it taking some code form another script, i just forgot to remove it. the messageUser.php shouldnt be there, Link to comment https://forums.phpfreaks.com/topic/98203-php-email-help/#findComment-503078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.