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.
Code:
<?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 Confirmationrn";
$message.="This is to confirm the order of:rn";
$message.="rn";
$message.="rn";
$message.="Quantity: ". $quantity . "rn";
$message.="Item: ". $item . "rn";
$message.="rn";
$message.="rn";
$message.="The address that this item will be invoiced to is as follows:rn";
$message.="rn";
$message.="rn";
$message.="" . $row['forename'] . " " . $row['surname'] . ".rn";
$message.="" . $row['fullAddress'] . ".rn";
$message.="" . $row['postCode'] . ".rn";
$message.="rn";
$message.="rn";
$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.rn";
}
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(Cool 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 ;