Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <head>
  5. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  6. <title>Kasaria - Adopt</title>
  7. <style type="text/css">
  8. body {
  9.     text-align:center;
  10. }
  11. </style>
  12.  
  13. </head>
  14.  
  15. <body>
  16.  
  17. <?php
  18. //include stuff
  19. require("includes/connect.php");
  20. require("includes/kasaria.php");
  21. require("includes/members.php");
  22.  
  23. if(isset($_GET['action']) && $_GET['action'] == "adopt"){
  24.     if(empty($_POST['color']) || empty($_POST['name']) || empty($_POST['species'])){
  25.         echo 'Please fill out all the fields!';
  26.         exit();
  27.     }
  28.     $newname = preg_replace('/[^a-zA-Z0-9_-\\s]/', '', mysql_real_escape_string($_POST['name']));
  29.     $speciesurl = getURL(mysql_real_escape_string($_POST['species']));
  30.     $user = getID($usernameglobal);    
  31.     $result = mysql_query("SELECT * FROM pets WHERE name = '$newname'") or die(mysql_error());
  32.     $numrows = mysql_num_rows($result);
  33.     if( $numrows > 0){
  34.         echo "Sorry, that pet name is taken. Please go back and try again.";
  35.     }
  36.     else {
  37.         $species = mysql_real_escape_string($_POST['species']);
  38.         $color = mysql_real_escape_string($_POST['color']);
  39.         mysql_query("INSERT INTO pets (name, speciesid, color, owner, level, hunger, happiness)
  40.         values ('$newname', '$species', '$color', '$user', '1', '0', '100')") or die(mysql_error());  
  41.         echo $newname . ' was sucessfully adopted!<br/><img src="images/' . $speciesurl . $_POST['color'] . '.png"><br/><a href="index.php">Home</a>';
  42.     }      
  43. }
  44.  
  45. else {
  46.     $result = mysql_query("SELECT * FROM species WHERE available = '1'") or die(mysql_error());
  47.     $numrows = mysql_num_rows($result);
  48.     if( $numrows > 0){
  49.         while($row = mysql_fetch_array( $result )){
  50.                 echo '<img src="images/' . strtolower($row['name']) . 'red.png">
  51.                 <img src="images/' . strtolower($row['name']) . 'yellow.png">
  52.                 <img src="images/' . strtolower($row['name']) . 'green.png">
  53.                 <img src="images/' . strtolower($row['name']) . 'blue.png"><br/>
  54.                 <form action="adopt.php?action=adopt" method="post"><input type="radio" name="color" value="red"> Red<br>
  55.                 <input type="radio" name="color" value="yellow"> Yellow<br>
  56.                 <input type="radio" name="color" value="green"> Green<br/>
  57.                 <input type="radio" name="color" value="blue"> Blue<br/>Name:<br/>
  58.                 <input type="text" name="name"/><input type="hidden" value="' . $row['id'] . '" name="species">
  59.                 <input type="submit" value="Submit" /></form>';
  60.     }}
  61.     else {
  62.         echo 'There are no pets available to adopt!';
  63.     }
  64. }?>
  65.  
  66.    
  67.    
  68. </body>
  69.  
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement