oneski Posted March 31, 2008 Share Posted March 31, 2008 Basically this page selects the name of a product from a pull down box and sends the variables 'stock' and 'quantity' to the process.php form which in turn forwards and email automatcially. I need this page to pull down other variables such as description, name and amountInStock when an item of stock is pulled down from the select box and forwarded to the process page. The process page selects data from the order page by: $quantity = $_POST['quantity']; $item = $_POST['stock']; i need the other variables to be selected the same way. <?php session_start(); include("header.php"); echo "<form action='process.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"); ?> Link to comment https://forums.phpfreaks.com/topic/98823-selecting-data-from-database/ Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 <?php $quantity = $_POST['quantity']; $item = $_POST['stock']; $con = makeConn(); $result = mysql_query("SELECT * FROM stock WHERE stockID = '".mysql_real_escape_string($item)."' LIMIT 1"; $row = mysql_fetch_array($result); $description = $row['description']; $name = $row['name']; $amountInStock = $row['amountInStock']; ?> Link to comment https://forums.phpfreaks.com/topic/98823-selecting-data-from-database/#findComment-505674 Share on other sites More sharing options...
oneski Posted March 31, 2008 Author Share Posted March 31, 2008 Ok i've implemented that, and my order.php code is still the same as before. The following error has popped up (Parse error: syntax error, unexpected ';' in C:\wamp\www\test\process2.php on line 12) Below is my process.php code: <?php session_start(); include("header.php"); if(isset($_SESSION['id'])){ $quantity = $_POST['quantity']; $item = $_POST['stock']; $con = makeConn(); $result = mysql_query("SELECT * FROM stock WHERE stockID = '".mysql_real_escape_string($item)."' LIMIT 1"; $row = mysql_fetch_array($result); $description = $row['description']; $name = $row['name']; $amountInStock = $row['amountInStock']; echo "You have ordered ". $quantity . " " . $item . " " . $name . ".<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");?> There is now two mysql selects there, the one rhodesa gave me and one to select users information. The users information is included within the email, im sure there is an easier way of doing this but im not to skilled with php, with only basic knowledge. So what i need this whole thing to do is. Order.php User selects item of stock from a pull down box which sends the following variables to process.php name, description, amountInStock (aswell as quantity and stock) but they get sent with the order.php Process.php use the variables to say what has been ordered and how many (echo "You have ordered ". $quantity . " " . $item . " " . $name . ".<br />" Then send an automatic email to the users email address and to the host's email address ($to ="" . $_SESSION['email'] . ", "; $to .= "pj@localhost" This email contains all the users details and the stock details. My code before rhodesa successfully held all the users details, but non of the code. Link to comment https://forums.phpfreaks.com/topic/98823-selecting-data-from-database/#findComment-505692 Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 The error is cus I forgot a parenthesis: $result = mysql_query("SELECT * FROM stock WHERE stockID = '".mysql_real_escape_string($item)."' LIMIT 1"; should be $result = mysql_query("SELECT * FROM stock WHERE stockID = '".mysql_real_escape_string($item)."' LIMIT 1"); Link to comment https://forums.phpfreaks.com/topic/98823-selecting-data-from-database/#findComment-505702 Share on other sites More sharing options...
oneski Posted March 31, 2008 Author Share Posted March 31, 2008 yeah thats worked, thanks for your help, much appreciated Link to comment https://forums.phpfreaks.com/topic/98823-selecting-data-from-database/#findComment-505749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.