fork download
  1. ////////////////////
  2. ///
  3. ///
  4. /////add.php////////
  5. <?php require ("umalik5_a1_lib.php"); ?>
  6. <?php
  7. if (empty($_POST)){
  8. top_header();
  9. form();
  10. valdator();
  11. bottom();
  12. }else{
  13. $vacant = valid();
  14. }if(empty($vacant)){
  15. dbs();
  16. header('Location: umalik5_a1_view.php');
  17. }else{
  18. top_header();
  19. form();
  20. valdator();
  21. bottom();
  22. }
  23. ?>
  24. ////////////////////////////////////////
  25. //
  26. //
  27. //
  28. ///lib.php///////////////////////////////
  29. <?php function top_header() { ?>
  30. <?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://w...content-available-to-author-only...3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  32. <html xmlns="http://w...content-available-to-author-only...3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
  33. <head>
  34. <title>Inventory Management (Assign1)</title>
  35. </head>
  36. <body>
  37. <?php } ?>
  38. <?php
  39. function product(){
  40. echo '<table cellspace="4">
  41. <tr>
  42. <td><a href="umalik5_a1_add.php">enter products </a></td>
  43. <td><a href="umalik5_a1_lib.php">products on sale</a></td>
  44. <td><a href="umalik5_a1_lib.php">discontinued products</a></td>
  45. <td><a href="umalik5_a1_view.php">view products</a></td>
  46. <td>Search description<input type="text" name="search"/></td>
  47. </tr>
  48. </table>';
  49. }?>
  50. <?php
  51. function form() {
  52. product();
  53. ?>
  54. <form action ="<?php echo $_SERVER[PHP_SELF] ?>" method="post">
  55. <table>
  56. <tr>
  57. <td align='right'>Item:</td>
  58. <td><input type="text" name="name" value="<?php echo $_POST[name]; ?>"/></td>
  59. </tr>
  60. <tr>
  61. <td align='right'>Company:</td>
  62. <td><input type="text" name="manufac" value="<?php echo $_POST[manufac] ;?>" /></td>
  63. </tr>
  64. <tr>
  65. <td align='right'>Model Code:</td>
  66. <td><input type="text" name="model" value="<?php echo $_POST[model] ;?>"/></td>
  67. </tr>
  68.  
  69. <tr>
  70. <td align='right'>Description:</td>
  71. <td><input type="text" name="descrip" value="<?php echo $_POST[descrip] ;?>"/> </td>
  72. </tr>
  73.  
  74. <tr>
  75. <td align='right'>In Stock:</td>
  76. <td><input type="text" name="onhand" value="<?php echo $_POST[onhand] ;?>"/> </td>
  77. </tr>
  78. <tr>
  79. <td align='right'>Reorder Level:</td>
  80. <td><input type="text" name="reorder" value="<?php echo $_POST[reorder] ;?>"/></td>
  81. </tr>
  82.  
  83. <tr>
  84. <td align='right'>Cost:</td>
  85. <td><input type="text" name="cost" value="<?php echo $_POST[cost] ;?>"/></td>
  86. </tr>
  87.  
  88. <tr>
  89. <td align='right'>Price:</td>
  90. <td><input type="text" name="price" value="<?php echo $_POST[price] ;?>"/></td>
  91. </tr>
  92. <tr>
  93. <td align='right'>On sale ? </td>
  94. <td><input type="checkbox" name="sale" value="y"<?php if ($_POST[sale] == 'y') echo 'checked="checked"' ; ?>/> </td>
  95. </tr>
  96. <tr>
  97. <td align='right'>Discontinued ? </td>
  98. <td><input type="checkbox" name="discont" value="y" <?php if ($_POST[discont] == 'y') echo 'checked="checked"' ; ?>/> </td>
  99. </tr>
  100. </table>
  101. <input type="submit" value="submit"/>
  102. </form>
  103. <?php } ?>
  104. <?php
  105. function valid (){
  106.  
  107. $vacant = array(); //create empty array
  108. if (!preg_match("/^[a-zA-Z ]+$/",$_POST[name])){
  109. array_push($vacant,"The Item name is invalid, will only accept letters and spaces only<br />");
  110. echo $vacant[0];
  111. }
  112. if (!preg_match("/^[-a-zA-Z ]+$/",$_POST[manufac])){
  113. array_push($vacant,"The Company Name is invalid, will only accept letters and/or dashes and/or spaces only<br />");
  114. echo $vacant[1];
  115. }
  116. if (!preg_match("/^[-a-zA-Z0-9 ]+$/",$_POST[model])){
  117. array_push($vacant,"The Model code is invalid, will only accept letters, dashes, digits and spaces only<br />");
  118. echo $vacant[2];
  119. }
  120. if (!preg_match("/^[a-zA-Z0-9,. ]+$/",$_POST[descrip])){
  121. array_push($vacant,"The Description is invalid, will only accept letters, digits, periods, commas, and spaces only<br />");
  122. echo $vacant[3];
  123. }
  124. if (!preg_match("/^[0-9]+$/",$_POST[onhand])){
  125. array_push($vacant,"The In Stock field is invalid, will only accept digits<br />");
  126. echo $vacant[4];
  127. }
  128. if (!preg_match("/^[0-9]+$/",$_POST[reorder])){
  129. array_push($vacant,"The Reorder Level field is invalid, will only accept digits<br />");
  130. echo $vacant[5];
  131. }
  132. if (!preg_match("/^[0-9]+\.[0-9]{2}$/",$_POST[cost])){
  133. array_push($vacant,"The Cost is invalid, will only accept digit(s) followed by a decimal ending with two digits ex: 5.99 or 650.54<br />");
  134. echo $vacant[6];
  135. }
  136. if (!preg_match("/^[0-9]+\.[0-9]{2}$/",$_POST[price])){
  137. array_push($vacant,"The Price is invalid, will only accept digit(s) followed by a decimal ending with two digits ex: 6.00 or 1250.66<br />");
  138. echo $vacant[7];
  139. }
  140.  
  141. ?>
  142. <?php
  143.  
  144. return $vacant;
  145. }
  146. ?>
  147. <?php
  148. function bottom(){
  149. ?>
  150. </body>
  151. </html>
  152. <?php
  153. }
  154. ?>
  155. <?php function connect(){
  156. $connect=mysql_connect("db-mysql.zenit",$me,$shh) or die(" <br />could not connect to database".mysql_error());
  157. mysql_select_db($me)or die('could not find database'.mysql_error());
  158. }
  159. ?>
  160. <?php
  161. function dbs(){
  162. ?>
  163. <?php
  164. connect();
  165. $insert="insert into inventory values('','$_POST[name]','$_POST[manufac]','$_POST[model]','$_POST[descrip]','$_POST[onhand]','$_POST[reorder]','$_POST[cost]','$_POST[price]','$_POST[sale]','$_POST[discont]')";
  166. mysql_query($insert) or die("could not execute query<br />".mysql_error());
  167. ?>
  168. <?php
  169. }
  170. ?>
  171. <?php
  172. function view(){
  173. connect();
  174. $select='select * from inventory';
  175. $admit=mysql_query($select) or die("<br /> could not complete query request <br />".mysql_error());
  176. ?>
  177. <table border='1'>
  178. <tr>
  179. <th>ID</th>
  180. <th>Item</th>
  181. <th>Company</th>
  182. <th>Model Code:</th>
  183. <th>Description</th>
  184. <th>In Stock</th>
  185. <th>Reorder Level</th>
  186. <th>Cost</th>
  187. <th>Price</th>
  188. <th>On Sale</th>
  189. <th>Discontinued</th>
  190. </tr>
  191.  
  192. <?php
  193. while($s = mysql_fetch_assoc($admit))
  194. {
  195. echo"<tr>
  196. <td>$s[id]</td>
  197. <td>$s[name]</td>
  198. <td>$s[manufac]</td>
  199. <td>$s[model]</td>
  200. <td>$s[descrip]</td>
  201. <td>$s[onhand]</td>
  202. <td>$s[reorder]</td>
  203. <td>$s[cost]</td>
  204. <td>$s[price]</td>
  205. <td>$s[sale]</td>
  206. <td>$s[discont]</td>
  207. </tr>";
  208. }
  209. echo"</table>";
  210. ?>
  211. <?php
  212. }
  213. ?>
  214. <?php
  215. function valdator(){//this function holds the validators
  216. ?>
  217. <p>
  218. <a href="http://v...content-available-to-author-only...3.org/check?uri=referer">
  219. <img src="http://w...content-available-to-author-only...3.org/Icons/valid-xhtml10"
  220. alt="Valid XHTML 1.0 Strict" height="31" width="88" />
  221. </a>
  222. <a href="http://j...content-available-to-author-only...3.org/css-validator/check/referer">
  223. <img style="border:0;width:88px;height:31px"
  224. src="http://j...content-available-to-author-only...3.org/css-validator/images/vcss-blue"
  225. alt="Valid CSS!" />
  226. </a>
  227. </p>
  228. <?php } ?>
  229. /////////////////////////////////////////////////////////////
  230. ///
  231. ///
  232. ///
  233. ////view.php////////////////////////////////////////////////
  234. <?php require ("umalik5_a1_lib.php"); ?>
  235. <?php top_header();?>
  236. <?php product();?>
  237. <?php view();?>
  238. <?php valdator();?>
  239. <?php bottom();?>
Runtime error #stdin #stdout 0.03s 13112KB
stdin
Standard input is empty
stdout
////////////////////
///
///
/////add.php////////

Warning: require(umalik5_a1_lib.php): failed to open stream: No such file or directory in /home/lgE4XZ/prog.php on line 5

Fatal error: require(): Failed opening required 'umalik5_a1_lib.php' (include_path='.:/usr/share/php5:/usr/share/php') in /home/lgE4XZ/prog.php on line 5