Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <tr>
  2. <th>Name</th>
  3. <th>Type</th>
  4. <th>DateOfBirth</th>
  5. <th>Description</th>
  6. <th>Photo</th>
  7. <th>Available</th>
  8. <th>Owner</th>
  9. <th>Adopt</th>
  10. <tr>
  11.  
  12. <?php
  13. error_reporting(E_ALL ^ E_DEPRECATED);//put in place due to previous error: Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO.
  14.  
  15. $hostname="localhost"; //local server name default localhost
  16. $username="root"; //mysql username default is root.
  17. $password=""; //blank if no password is set for mysql.
  18. $database="dc2410"; //database name which you created
  19.  
  20. mysql_connect($hostname, $username, $password);
  21. mysql_select_db($database);
  22.  
  23. $sql=mysql_query("SELECT * FROM `animal` WHERE `available` = 'Yes'");
  24.  
  25. while($animal=mysql_fetch_assoc($sql)){
  26.  
  27. echo"<tr>";
  28.  
  29. $animal['animalID'];
  30. echo "<td>".$animal['name']."</td>";
  31. echo "<td>".$animal['type']."</td>";
  32. echo "<td>".$animal['dateofbirth']."</td>";
  33. echo "<td>".$animal['description']."</td>";
  34. echo "<td>"?> <img src="<?php echo $animal['photo'] ?>" width="100px" height="100px"/> <?php "</td>";
  35. echo "<td>".$animal['available']."</td>";
  36. echo "<td>".$animal['owner']."</td>";
  37. ?>
  38. <td><form><input type="submit" value="Adopt" name="adopt" onClick="
  39. <?php
  40.  
  41. $req=mysql_query("INSERT INTO adoptionrequest(userID, animalID, approved) VALUES ('1','".$animal['animalID']."','Awaiting Approval')");
  42.  
  43. ?>
  44. " ></form></td>
  45. <?php
  46. echo"<tr>";
  47.  
  48. }
  49.  
  50. ?>
  51.  
  52. </table>
  53.  
  54. $sub = intval($_POST['sub']);
  55. $selected = intval($_POST['selected']);
  56. if ($sub == 1){
  57. mysql_query("INSERT INTO adoptionrequest(`userID`, `animalID`, `approved`) VALUES ('1','$selected','Awaiting Approval')");
  58. if(mysql_errorno() > 0){echo mysql_error();}
  59. }
  60.  
  61.  
  62. echo '<form action="#" method="post" ><input type="hidden" name="sub" value="1"><table>';
  63. $results = mysql_query("SELECT `animalID`, `name`,`type`,`dateofbirth`,`description`,`photo`,`available`,`owner` FROM `animal` WHERE `available` = 'Yes'");
  64. while($animal=mysql_fetch_assoc($results, MYSQL_NUM)){
  65. echo <<<EOT
  66. <tr><td>$animal[0]</td>
  67. <td>$animal[1]</td>
  68. <td>$animal[2]</td>
  69. <td>$animal[3]</td>
  70. <td>$animal[4]</td>
  71. <td><img width="100px" height="100px" src="$animal[5]" alt="$animal[1]"/></td>
  72. <td>$animal[6]</td>
  73. <td>.$animal[7]</td>
  74. <td><button type="submit" name="selected" value="$animal[0]"/></td></tr>
  75. EOT;
  76.  
  77. }
  78.  
  79. die("Couldn't enter data: ".$conn->error);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement