The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled PHP Code
Posted by: nom | March 30, 2010 @ 5:07am
PHP Code
[
Download
]
<?php session_start(); ?> <html> <head> <title>Canteen Orders</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> function ShowOrder(theOption){ alert ("You have ordered " + theOption[theOption.selectedIndex].value +" "+theOption.name); } var orders = new Array(); var products = new Array(); function LoadOrderArray(theForm){ var count=0; for (i=0;i<document.orderform.elements.length-3;i++){//process the form to give a total in the box qty = document.orderform.elements[i].value; if (qty > 0){ orders[count]=qty; productno = document.orderform.elements[count].value; products[count] = productno; count++; } //ends the if }//ends the for loop // document.orderform.orderarray.value = orders; // document.orderform.productsarray.value = products; alert ("thank you for you order " ); return true; } </script> </head> <body bgcolor="#00CC00"> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="CANTEEN"; // Database name $tbl_name="STUDENT"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $username=$_GET['StudentName']; $sql="SELECT * FROM student WHERE STUDENTID='$username'"; $result=mysql_query($sql); $row = mysql_fetch_array($result, MYSQL_ASSOC); echo "<BR> the user name is "; echo $row['FIRSTNAME']; _SESSION['studentsname']=$row['FIRSTNAME']; //$current = session_register("username"); $sql="SELECT * FROM STUDENT WHERE STUDENTID='$username'"; $result=mysql_query($sql); $count=mysql_num_rows($result); echo "<input type = \"hidden\" name = \"StudentName\" value =\" "; if ($count==0){ echo "ERROR"; }else{ $row = mysql_fetch_array($result, MYSQL_ASSOC); $FName = $row['FIRSTNAME']; $LName = $row['LASTNAME']; echo "Welcome to Lunch Orders R us "; echo $FName; } ?> <form action="backup/studentchangepassword.php" method="get" name="form3" target="mainFrame" > <input type="submit" name="Submit3" value="Change Password"> </form> <form action="processorders.php?order=" method = "get" name="orderform" onSubmit="LoadOrderArray(this)"> <?php $hot = "Yes"; $cat = "Savory"; $ordersql="SELECT PRODUCTID, PRODUCTNAME, CATEGORY, PRICE, HOT FROM PRODUCTS ORDER BY CATEGORY"; $orderresult=mysql_query($ordersql); $ordercount=mysql_num_rows($orderresult); echo "<table border = '1'><tr><TD> Qty <TD> Product Name <TD> Category <TD> Price <TD> Hot "; while($row = mysql_fetch_array($orderresult, MYSQL_ASSOC)) { if ($row['HOT']=="Y") $hot = "Yes"; else $hot = "No"; switch ($row['CATEGORY']){ case 1: $cat = "Savory"; break; case 2: $cat = "Sweet"; break; case 3: $cat = "Drink"; break; default: $cat="Unknown"; }//ends the switch echo "<TR> <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> <input type = 'hidden' name = '{$row['PRODUCTID']}' VALUE = '{$row['PRODUCTID']}'> <TD> {$row['PRODUCTNAME']} <TD> {$cat} <TD> {$row['PRICE']} <TD> {$hot} "; } //ends the while echo "<TR><TD colspan = '6'> "; ?> <input type = "hidden" name = "orderarray"> <input type = "hidden" name = "productarray"> Total: <input type = "text" name ="Total"> <input type ="submit" name ="submit" value = "Process your order" onClick="LoadOrderArray(this)" > </form> </body> </html>
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.41 / 8
63 Votes
http://codebin.yi.org/564
page generated in 0.01 seconds