Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors',1);
  4. include('dbpass.php');
  5. $mysqli = new mysqli('oniddb.cws.oregonstate.edu', 'hengs-db', $dbpass, 'hengs-db');
  6. if ($mysqli->connect_errno) {
  7. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  8. } else echo "Connected to database<br>";
  9. ?>
  10.  
  11. <HTML>
  12. <BODY>
  13. <H1>UNIT TESTING FOR SHOW.PHP</H1>
  14.  
  15.  
  16. <SECTION="testSuite">
  17. <?php
  18.  
  19.  
  20.  
  21.  
  22.  
  23. /*Tests updating food to database
  24. function updateFood($status, $servings, $eatBy, $imageURL){
  25. global $mysqli; //access the mysqli object
  26. if (!($stmt = $mysqli->prepare("INSERT INTO food_items_available(food_type, servings, eat_by, image_URL) VALUES (?,?,?,?)"))) {
  27. echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
  28. }
  29. if (!$stmt->bind_param("siss", $foodType, $servings, $eatBy, $imageURL)) {
  30. echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
  31. }
  32. if (!$stmt->execute()) {
  33. echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
  34. } else {
  35. echo '<div class="alert alert-success" role="alert"><span class="glyphicon glyphicon-ok"></span>
  36. Thanks! Food items were successfully submitted!</div>';
  37. }
  38. $stmt->close();
  39. }
  40. */
  41. $unreserved=("SELECT id FROM food_items_available WHERE status=NULL");
  42.  
  43. //$new_array[ $row['id']] = $row;
  44. //while( $row = mysql_fetch_assoc( $result)){
  45. // $new_array[] = $row; // Inside while loop
  46. //}
  47.  
  48. $list = $mysqli->query($unreserved);
  49. if($list->num_rows>0){
  50. while($rows = $list->fetch_assoc()){
  51. $new_array[] = $rows[id];
  52. }
  53.  
  54. foreach($new_array as $value){
  55. updateFood(1, "Bill Cosby", $value)
  56. }
  57.  
  58.  
  59.  
  60. function updateFood($statusSet, $customerName, $value){
  61. global $mysqli;
  62. if (!($updateQuery = $mysqli->prepare("UPDATE food_items_available SET status=?, customer=? WHERE id=?"))) {
  63. echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
  64. }
  65. $statusSet = 1;
  66.  
  67. if (!$updateQuery->bind_param("isi", $statusSet, $customerName, $value)) {
  68. echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
  69. }
  70. if (!$updateQuery->execute()) {
  71. echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
  72. }else{
  73. echo '<div class="alert alert-success" role="alert"><span class="glyphicon glyphicon-ok"></span>
  74. Thanks! Food item id#'.$value.' was successfully reserved by '.$customerName.'!!!</div>';
  75. }
  76. $updateQuery->close();
  77. }
  78. ?>
  79.  
  80. </SECTION>
  81. </BODY>
  82. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement