Help, Not sure how to go about inserting data.
Posted: Thu Apr 09, 2009 12:31 pm
Hi, i've started using php for a project for school and I have to create an online shop as it were. There are three tables customer, stock and order.
Customer Fields are :CustomerID Lastname Firstname Username Password Address1 Address2 Postcode Phone Email
Order fields are : OrderID CustomerID ProductID OrderDate Text Font Picture Filled
Stock fields are : ProductID ProductName StockAmount PricePerTshirt
So i've been trying to create an order form. Wherein customers can
PART ONE named Placeorder.php </form></table></body></html>
Part Two named AddOrder
Any more information needed please just say.
Customer Fields are :CustomerID Lastname Firstname Username Password Address1 Address2 Postcode Phone Email
Order fields are : OrderID CustomerID ProductID OrderDate Text Font Picture Filled
Stock fields are : ProductID ProductName StockAmount PricePerTshirt
So i've been trying to create an order form. Wherein customers can
- put a hyperlink to an image
put in text that they want on their tshirt
choose the font that they want on their tshirt
and choose which type (which is just sizes and whether they're male or female.)
PART ONE named Placeorder.php
Code: Select all
<html>
<head>
<title>Home Printed Tshirts</title>
</head>
<body>
<h3>Order a Black Confetti Home Printed Tshirt!</h3>
<h4>Order Form </h4>
<table>
<form name="frmPlaceorder" action="AddOrder.php" method="post">
<tr>
<td>Select Font and Tshirt size in the Form Below</td>
</tr>
Hyperlink to Picture: <input name="hyperlink" type="text" /><br />
Text to be on your Tshirt(This can be no longer than 50 Characters.(that means spaces are included.):<br />
<textarea name="text_on_tshirt" rows="15" cols="40"></textarea>
<br/>
<tr>
<td><select name="ChooseFont">
<option value="Arial Black"Arial Black</option>;
<option value="Verdana"Verdana</option>;
<option value="Comic Sans MS"Comic Sans MS</option>;
<option value="Calibri"Calibri</option>;
<option value="Courier New"Courier New</option>;
<option value="Cambria"Cambria</option>;
<option value="Tahoma"Tahoma</option>;
<option value="Trebuchet MS"Trebuchet MS</option>;
<option value="Windings"Windings</option>;
<option value="Algerian"Algerian</option>;
<tr>
<td> </td>
</tr>
<tr>
<td><select name="selectTshirt">
Code: Select all
<?PHP</li><li style=\"\" class=\"li1\"> //variable to check if no tshirts:</li><li style=\"\" class=\"li2\"> $flag = 1;</li><li style=\"\" class=\"li1\"> //connect to database to obtain list of all Ts'</li><li style=\"\" class=\"li2\"> $dbh = mysql_connect("localhost","afearon582","67tyu89");</li><li style=\"\" class=\"li1\"> mysql_select_db("e1420022_afearon582", $dbh); </li><li style=\"\" class=\"li2\"> //create sql to list tshirts in order of product id</li><li style=\"\" class=\"li1\"> $sql = "SELECT * FROM stock WHERE StockAmount>'0' ";</li><li style=\"\" class=\"li2\"> $result=mysql_query($sql);</li><li style=\"\" class=\"li1\"> //no. of records found</li><li style=\"\" class=\"li2\"> $num=mysql_numrows($result);</li><li style=\"\" class=\"li1\"> //get details</li><li style=\"\" class=\"li2\"> if($num > 0) {</li><li style=\"\" class=\"li1\"> $i=0;</li><li style=\"\" class=\"li2\"> while ($i < $num) {</li><li style=\"\" class=\"li1\"> //get tshirt details</li><li style=\"\" class=\"li2\"> $ProductID = mysql_result($result,$i,"ProductID");</li><li style=\"\" class=\"li1\"> $ProductName = mysql_result($result,$i,"ProductName");</li><li style=\"\" class=\"li2\"> //add details to HTML listbox:</li><li style=\"\" class=\"li1\"> echo "<option value='". $ProductID . "'>".$ProductName."</option>";</li><li style=\"\" class=\"li2\"> $i++;</li><li style=\"\" class=\"li1\"> //add details to HTML listbox:</li><li style=\"\" class=\"li2\"> </li><li style=\"\" class=\"li1\"> }</li><li style=\"\" class=\"li2\"> }</li><li style=\"\" class=\"li1\"> else {</li><li style=\"\" class=\"li2\"> //no tshirts found:</li><li style=\"\" class=\"li1\"> echo "<option value=''>No Tshirts In Stock!!</option>";</li><li style=\"\" class=\"li2\"> $flag = 0;</li><li style=\"\" class=\"li1\"> }</li><li style=\"\" class=\"li2\"> ?></li><li style=\"\" class=\"li1\"> //close database</li><li style=\"\" class=\"li2\"> mysql_close();</li><li style=\"\" class=\"li1\"> ?></li><li style=\"\" class=\"li2\"> </select></td></li><li style=\"\" class=\"li1\"> </tr></li><li style=\"\" class=\"li2\"> <tr></li><li style=\"\" class=\"li1\"> <td> </td></li><li style=\"\" class=\"li2\"> </tr></li><li style=\"\" class=\"li1\"> <tr></li><li style=\"\" class=\"li2\"> <td><a href="http://afearon582.methody.org/home/menu.php">Cancel and Return to Main Menu </a></td></li><li style=\"\" class=\"li1\"> </tr></li><li style=\"\" class=\"li2\"> <?php</li><li style=\"\" class=\"li1\"> </li><li style=\"\" class=\"li2\"> if($flag == 1) {</li><li style=\"\" class=\"li1\"> ?></li><li style=\"\" class=\"li2\"> <tr></li><li style=\"\" class=\"li1\"> <td><input type='submit' name='Submit' value='Click to Continue' /></td></li><li style=\"\" class=\"li2\"> </tr></li><li style=\"\" class=\"li1\"> <? } ?>Part Two named AddOrder
Code: Select all
<?PHP
session_start();
header("Cache-control: private");
//get new order details:
$ProductID = trim($_POST['SelectTshirt']);
$OrderDate= trim($_POST['txtOrderDate']);
$Text = trim($_POST['text_on_shirt']);
$Font = trim($_POST['ChooseFont']);
$Picture = trim($_POST['hyperlink']);
//connect to database and add new customer details
$dbh = mysql_connect("localhost","afearon582","67tyu89") or die('Sorry, could not connect:'.mysql_error());
mysql_select_db("e1420022_afearon582", $dbh);
//check if needing to add a new customer, or amend existing customer
$sql = "INSERT INTO order VALUES(NULL, '$ProductID',CURDATE(),'$Text','$Font','$Picture')";
if($result=mysql_query($sql))
{
echo "<br />Order successfully added!";
}
else
{
echo "<br />Sorry - Order not added! Reason: " . mysql_error();
//close database
mysql_close();
}
header("Location: index2.php");
?>