SHOW:
|
|
- or go back to the newest paste.
1 | - | $query = $pdo->prepare("SELECT * FROM users WHERE username=:username"); |
1 | + | <?php |
2 | - | $query->bindValue(":username", $username, PDO::PARAM_STR); |
2 | + | |
3 | - | $query->execute(); |
3 | + | $pdo = new PDO("mysql:host=localhost;dbname=_fantapc", '_fpcroot', 'password'); |
4 | - | $row = $query->fetchAll(); |
4 | + | |
5 | if(isset($_POST['addcard'])) { | |
6 | $cardname = $_POST['card_input']; | |
7 | $rarity = $_POST['rarity_input']; | |
8 | $image = $_FILES['file']['name']; | |
9 | ||
10 | $query = $pdo->prepare("INSERT INTO cards (name,rarity,img) VALUES (:name,:rarity,:img)"); | |
11 | $query->bindValue(":name", $cardname, PDO::PARAM_STR); | |
12 | $query->bindValue(":rarity", $rarity, PDO::PARAM_STR); | |
13 | $query->bindValue(":img", $image, PDO::PARAM_STR); | |
14 | $query->execute(); | |
15 | ||
16 | if ($_FILES["file"]["error"] > 0) { | |
17 | echo "Error: " . $_FILES["file"]["error"] . "<br>"; | |
18 | } | |
19 | ||
20 | else { | |
21 | echo "Upload: " . $_FILES["file"]["name"] . "<br>"; | |
22 | echo "Type: " . $_FILES["file"]["type"] . "<br>"; | |
23 | echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; | |
24 | echo "Stored in: " . $_FILES["file"]["tmp_name"]; | |
25 | } | |
26 | ||
27 | $allowedExts = array("gif", "jpeg", "jpg", "png"); | |
28 | $temp = explode(".", $_FILES["file"]["name"]); | |
29 | $extension = end($temp); | |
30 | if ((($_FILES["file"]["type"] == "image/gif") | |
31 | || ($_FILES["file"]["type"] == "image/jpeg") | |
32 | || ($_FILES["file"]["type"] == "image/jpg") | |
33 | || ($_FILES["file"]["type"] == "image/pjpeg") | |
34 | || ($_FILES["file"]["type"] == "image/x-png") | |
35 | || ($_FILES["file"]["type"] == "image/png")) | |
36 | && in_array($extension, $allowedExts)) { | |
37 | if ($_FILES["file"]["error"] > 0) { | |
38 | echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; | |
39 | } | |
40 | ||
41 | else { | |
42 | echo "Upload: " . $_FILES["file"]["name"] . "<br>"; | |
43 | echo "Type: " . $_FILES["file"]["type"] . "<br>"; | |
44 | echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; | |
45 | echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; | |
46 | ||
47 | if (file_exists("upload/" . $_FILES["file"]["name"])) { | |
48 | echo $_FILES["file"]["name"] . " already exists. "; | |
49 | } | |
50 | ||
51 | else { | |
52 | move_uploaded_file($_FILES["file"]["tmp_name"], | |
53 | "upload/" . $_FILES["file"]["name"]); | |
54 | echo "Stored in: " . "/opt/lampp/htdocs/andreas/fantasicapricecheck/upload/" . $_FILES["file"]["name"]; | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | else { | |
60 | echo "Invalid file"; | |
61 | } | |
62 | } | |
63 | ||
64 | ?> | |
65 | ||
66 | <h1>Add cards</h1> | |
67 | ||
68 | <form action="index.php?page=addcards" method="post" enctype="multipart/form-data"> | |
69 | <table> | |
70 | <tr> | |
71 | <td>cardname: </td><td> <input type="text" name="card_input"></td></tr> | |
72 | <tr> | |
73 | <td>rarity: </td><td> <select name="rarity_input"> | |
74 | <option value="1">1 star</option> | |
75 | <option value="2">2 star</option> | |
76 | <option value="3">3 star</option> | |
77 | <option value="4">4 star</option> | |
78 | <option value="5">5 star</option> | |
79 | <option value="6">6 star</option> | |
80 | <option value="7">7 star</option> | |
81 | </select></td></tr> | |
82 | <tr> | |
83 | <td>image: </td><td><input type="file" name="file" id="file"></td></tr> | |
84 | <tr> | |
85 | <td></td><td> | |
86 | <input type="hidden" name="addcard" value="1"> | |
87 | <input type="submit" value="add card!"></td> | |
88 | </tr></table></form> |