Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <?php
  2. $self = $_SERVER['PHP_SELF'];
  3.  
  4. function insertRecord($pName, $pSpecies, $pBreed, $pPrice, $pImage){
  5. $insertQuery = "INSERT into tblPets (petName, petSpecies, petBreed, petPrice, petImage)
  6. VALUES ('$pName', '$pSpecies', '$pBreed', '$pPrice', '$pImage')";
  7.  
  8. $result = mysql_query($insertQuery);
  9. }
  10.  
  11.  
  12.  
  13. //--------Connecting to MYSQL -----------------
  14. $host = "kate.ict.op.ac.nz";
  15.  
  16. $user = "randaaj1";
  17.  
  18. $password = "randaaj1";
  19.  
  20.  
  21. $connection = mysql_connect($host, $user, $password)
  22. or die ("Couldn't select database");
  23.  
  24. //echo ("<p>Connecting to MYSQL...</p>");
  25.  
  26. //----------Database Connection------------------
  27.  
  28. $database = "randaaj1_in612";
  29.  
  30. $db = mysql_select_db($database, $connection)
  31. or die ("Could'nt select database");
  32.  
  33. //echo ("<p>Connecting to Database...</p>");
  34.  
  35. //-----------Drop The Table-----------------------
  36.  
  37. $dropTable = "DROP TABLE tblPets";
  38.  
  39. $result = mysql_query($dropTable);
  40.  
  41. //echo ("<p>Clean Out Old Table(s)</p>");
  42.  
  43.  
  44.  
  45. //-----------Create Table-----------------------
  46.  
  47. $createTable = "CREATE TABLE tblPets
  48. (
  49. petID INT(6) NOT NULL AUTO_INCREMENT,
  50. petName VARCHAR(20) NOT NULL,
  51. petSpecies VARCHAR(20) NOT NULL,
  52. petBreed VARCHAR(20) NOT NULL,
  53. petPrice DECIMAL(7,2)NOT NULL,
  54. petImage VARCHAR(20) NOT NULL,
  55.  
  56. PRIMARY KEY(petID)
  57. )";
  58.  
  59. $result = mysql_query($createTable);
  60.  
  61. //echo ("<p>Creating Pet Table...</p>");
  62.  
  63.  
  64. //-----------Table Structure---------------------
  65.  
  66. $selectString = "SHOW COLUMNS FROM tblPets";
  67. $result = mysql_query($selectString);
  68.  
  69. //echo ("<p>Table Structure...</p>");
  70.  
  71. //-----------Display Table---------------------
  72. echo ("<table border = '0' cellpadding ='0'>");
  73. while ($row = mysql_fetch_row($result)){
  74. echo ("<tr>");
  75. foreach($row as $value)
  76. echo("<td>$value</td>");
  77. echo("</tr>");
  78. }
  79. echo ("</table>");
  80.  
  81. //-----------Inserting Table Records-----------------------------------
  82.  
  83. insertRecord('Buttons', 'Bird', 'Budgie', '40.00', 'buttons.jpg');
  84. insertRecord('Bob', 'Guinea Pig', 'English Cavy', '10.00', 'bob.jpg');
  85. insertRecord('Elmer', 'Guinea Pig', 'English Cavy', '10.00', 'elmer.jpg');
  86. insertRecord('Fido', 'Dog', 'Poodle', '300.00', 'fido.jpg');
  87. insertRecord('Flame', 'Guinea Pig', 'English Cavy', '10.00', 'flame.jpg');
  88. insertRecord('Fluffy', 'Cat', 'Siamese', '100.00', 'fluffy.jpg');
  89. insertRecord('Glug', 'Fish', 'Gold Fish', '20.00', 'glug.jpg');
  90. insertRecord('Lachien', 'Dog', 'Poodle', '300.00', 'lachien.jpg');
  91. insertRecord('Mewmew', 'Cat', 'Siamese', '100.00', 'mewmew.jpg');
  92. insertRecord('Mouser', 'Cat', 'Siamese', '100.00', 'mouser.jpg');
  93. insertRecord('Othello', 'Fish', 'Gold Fish', '20.00', 'othello.jpg');
  94. insertRecord('Polly', 'Bird', 'Budgie', '40.00', 'polly.jpg');
  95. insertRecord('Snoopy', 'Dog', 'Jack Russell', '200.00', 'snoopy.jpg');
  96. insertRecord('Trigger', 'Horse', 'Przewalski', '5000.00', 'trigger.jpg');
  97. insertRecord('Zippy', 'Horse', 'Przewalski', '5000.00', 'zippy.jpg');
  98. insertRecord('Harry', 'Horse', 'Przewalski', '8000.00', 'harry.jpg');
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. Function search(){
  106.  
  107. echo("<form action = '$self' method='POST'>");
  108. echo("<tr><th>
  109. <fieldset>
  110. Species:
  111. <input type='text' name='textSearch' size='30'>
  112. <input type='submit' name='seachNow' value='Search Now'>
  113. </fieldset></th></tr>");
  114. echo("</form>");
  115.  
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. Function display(){
  125. echo("<form action = '$self' method='POST'>");
  126. $text = $_POST['textSearch'];
  127.  
  128.  
  129. //-----------Select All Records--------------
  130.  
  131. $selectString = "SELECT * FROM tblPets";
  132. $result = mysql_query($selectString);
  133. echo "<br>";
  134.  
  135.  
  136. //-----------Display Table---------------------
  137. //
  138. echo ("<table border = '2' cellpadding ='10'>");
  139. echo("<tr><th>ID</th><th>Name</th><th>Species</th><th>Breed</th><th>Price</th><th>Image-Name</th><th>Image</th></tr>");
  140. while ($row = mysql_fetch_row($result)){
  141. echo ("<tr>");
  142. foreach($row as $value){
  143. echo("<td>$value</td>");
  144. }
  145. echo "<td><img src = images/$value></td>"; //Displays the last value (image) in a new field
  146. echo("</tr>");
  147. }
  148. echo ("</table>");
  149. echo("</form>");
  150.  
  151. }
  152.  
  153.  
  154.  
  155. if (isset($_POST['searchNow'])){
  156. display();
  157. }else{
  158. search();
  159.  
  160. }
  161.  
  162.  
  163. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement