Advertisement
Sparkster

Untitled

Jul 24th, 2013
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. if ($_SESSION['username'] != 'admin') {
  4.     echo "<img src='upload/abel.gif' /><h1>This is not the page you are looking for <a href='index.php'>home</a></h1>";
  5.     echo "<meta http-equiv='refresh' content='1; url=index.php'>";
  6. }
  7.     else {
  8.      
  9. $pdo = new PDO("mysql:host=localhost;dbname=fantapc", 'fpcroot', '');
  10.  
  11. function image_upload($name, $tmpname) {
  12.         move_uploaded_file($tmpname, "upload/" . $name);
  13.         // echo "Stored in: " . "upload/" . filename;
  14.         return "upload/" . $name;
  15. }
  16.  
  17. if(isset($_POST['addcard'])) {
  18.     $cardname = $_POST['card_input'];
  19.     $rarity = $_POST['rarity_input'];
  20.     $image_front = image_upload($_FILES['image_front']['name'], $_FILES['image_front']['tmpname']);
  21.     $image_back = image_upload($_FILES['image_back']['name'], $_FILES['image_back']['tmpname']);
  22.     $image_avatar = image_upload($_FILES['image_avatar']['name'], $_FILES['image_avatar']['tmpname']);
  23.     $image_sprite = image_upload($_FILES['image_sprite']['name'], $_FILES['image_sprite']['tmpname']);
  24.  
  25.     $query = $pdo->prepare("INSERT INTO cards (name,rarity,img_front,img_back,img_avatar,img_sprite) VALUES (:name,:rarity,:img_front,:img_back,:img_avatar,:img_sprite)");
  26.     $query->bindValue(":name", $cardname, PDO::PARAM_STR);
  27.     $query->bindValue(":rarity", $rarity, PDO::PARAM_STR);
  28.     $query->bindValue(":img_front", $image_front, PDO::PARAM_STR);
  29.     $query->bindValue(":img_back", $image_back, PDO::PARAM_STR);
  30.     $query->bindValue(":img_avatar", $image_avatar, PDO::PARAM_STR);
  31.     $query->bindValue(":img_sprite", $image_sprite, PDO::PARAM_STR);
  32.     $query->execute();
  33. } else { echo "no files"; }
  34.  
  35. ?>
  36.  
  37. <h1>Add cards</h1>
  38.  
  39. <form action="index.php?page=addcards" method="post" enctype="multipart/form-data">
  40.     <table>
  41.     <tr>
  42.         <td>cardname: </td><td> <input type="text" name="card_input"></td></tr>
  43.     <tr>
  44.         <td>rarity: </td><td>   <select name="rarity_input">
  45.                                 <option value="1">1 star</option>
  46.                                 <option value="2">2 star</option>
  47.                                 <option value="3">3 star</option>
  48.                                 <option value="4">4 star</option>
  49.                                 <option value="5">5 star</option>
  50.                                 <option value="6">6 star</option>
  51.                                 <option value="7">7 star</option>
  52. </select></td></tr>
  53.     <tr>
  54.         <td>card front: </td><td><input type="file" name="image_front" id="file"></td></tr>
  55.     <tr>
  56.         <td>card back: </td><td><input type="file" name="image_back" id="file"></td></tr>
  57.     <tr>
  58.         <td>avatar: </td><td><input type="file" name="image_avatar" id="file"></td></tr>
  59.     <tr>
  60.         <td>gif sprite: </td><td><input type="file" name="image_sprite" id="file"></td></tr>
  61.     <tr>
  62.         <td></td><td>
  63.                     <input type="hidden" name="addcard" value="1">
  64.                     <input type="submit" value="add card!"></td>
  65. </tr></table></form>
  66.  
  67. <? } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement