1. <?php session_start(); ?>
  2. <html>
  3. <head>
  4. <title>Canteen Orders</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6.  
  7. <script language="JavaScript">
  8.  
  9. function ShowOrder(theOption){
  10. alert ("You have ordered " + theOption[theOption.selectedIndex].value +" "+theOption.name);
  11. }
  12. var orders = new Array();
  13. var products = new Array();
  14.  
  15. function LoadOrderArray(theForm){
  16. var count=0;
  17. for (i=0;i<document.orderform.elements.length-3;i++){//process the form to give a total in the box
  18. qty = document.orderform.elements[i].value;
  19. if (qty > 0){
  20. orders[count]=qty;
  21. productno = document.orderform.elements[count].value;
  22. products[count] = productno;
  23. count++;
  24. } //ends the if
  25. }//ends the for loop
  26. // document.orderform.orderarray.value = orders;
  27. // document.orderform.productsarray.value = products;
  28. alert ("thank you for you order " );
  29. return true;
  30. }
  31.  
  32.  
  33. </script>
  34.  
  35.  
  36. </head>
  37.  
  38. <body bgcolor="#00CC00">
  39. <?php
  40. $host="localhost"; // Host name
  41. $username=""; // Mysql username
  42. $password=""; // Mysql password
  43. $db_name="CANTEEN"; // Database name
  44. $tbl_name="STUDENT"; // Table name
  45. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  46. mysql_select_db("$db_name")or die("cannot select DB");
  47.  
  48. // username and password sent from form
  49. $username=$_GET['StudentName'];
  50.  
  51. $sql="SELECT * FROM student WHERE STUDENTID='$username'";
  52. $result=mysql_query($sql);
  53. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  54. echo "<BR> the user name is ";
  55. echo $row['FIRSTNAME'];
  56.  
  57. _SESSION['studentsname']=$row['FIRSTNAME'];
  58.  
  59.  
  60. //$current = session_register("username");
  61. $sql="SELECT * FROM STUDENT WHERE STUDENTID='$username'";
  62. $result=mysql_query($sql);
  63. $count=mysql_num_rows($result);
  64. echo "<input type = \"hidden\" name = \"StudentName\" value =\" ";
  65.  
  66.  
  67. if ($count==0){
  68. echo "ERROR";
  69. }else{
  70. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  71. $FName = $row['FIRSTNAME'];
  72. $LName = $row['LASTNAME'];
  73. echo "Welcome to Lunch Orders R us ";
  74. echo $FName;
  75.  
  76. }
  77.  
  78. ?>
  79.  
  80. <form action="backup/studentchangepassword.php" method="get" name="form3" target="mainFrame" >
  81. <input type="submit" name="Submit3" value="Change Password">
  82. </form>
  83.  
  84. <form action="processorders.php?order=" method = "get" name="orderform" onSubmit="LoadOrderArray(this)">
  85. <?php
  86. $hot = "Yes";
  87. $cat = "Savory";
  88. $ordersql="SELECT PRODUCTID, PRODUCTNAME, CATEGORY, PRICE, HOT FROM PRODUCTS ORDER BY CATEGORY";
  89. $orderresult=mysql_query($ordersql);
  90. $ordercount=mysql_num_rows($orderresult);
  91. echo "<table border = '1'><tr><TD> Qty <TD> Product Name <TD> Category <TD> Price <TD> Hot ";
  92. while($row = mysql_fetch_array($orderresult, MYSQL_ASSOC))
  93. {
  94. if ($row['HOT']=="Y")
  95. $hot = "Yes";
  96. else
  97. $hot = "No";
  98. switch ($row['CATEGORY']){
  99. case 1: $cat = "Savory"; break;
  100. case 2: $cat = "Sweet"; break;
  101. case 3: $cat = "Drink"; break;
  102. default: $cat="Unknown";
  103. }//ends the switch
  104.  
  105.  
  106. echo "<TR>
  107. <TD> <select name = '{$row['PRODUCTNAME'] } ' onChange='ShowOrder(this)'><option value = 0>0<option value = 1>1<option value = 2>2 <option value = 3>3</select>
  108. <input type = 'hidden' name = '{$row['PRODUCTID']}' VALUE = '{$row['PRODUCTID']}'>
  109. <TD> {$row['PRODUCTNAME']}
  110. <TD> {$cat}
  111. <TD> {$row['PRICE']}
  112. <TD> {$hot} ";
  113.  
  114.  
  115.  
  116.  
  117.  
  118. } //ends the while
  119.  
  120. echo "<TR><TD colspan = '6'> ";
  121.  
  122. ?>
  123. <input type = "hidden" name = "orderarray">
  124. <input type = "hidden" name = "productarray">
  125. Total: <input type = "text" name ="Total">
  126. <input type ="submit" name ="submit" value = "Process your order" onClick="LoadOrderArray(this)" >
  127. </form>
  128.  
  129. </body>
  130. </html>
  131.