-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodajAutomobil.php
71 lines (64 loc) · 2.26 KB
/
dodajAutomobil.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require ('baza.php');
require('nav.php');
$sql = "select * from marka_automobila";
$results = $con->query($sql)->fetch_all(MYSQLI_ASSOC);
?>
<div class="container mt-5 form-container">
<h2 class="mb-5">Automobil</h2>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="role">Marka automobila:</label>
<select class="form-control" id="brand" name="brand" required>
<option value="">---</option>
<?php
foreach ($results as $result):
?>
<option value="<?= $result["id"] ?>"><?= $result["naziv"] ?></option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<label for="name">Naziv:</label>
<input type="text" class="form-control" id="name" name="name" required/>
</div>
<div class="form-group">
<label for="year">Godište:</label>
<input type="text" class="form-control" id="year" name="year" required/>
</div>
<div class="form-group">
<label for="price">Cijena po satu:</label>
<input type="text" class="form-control" id="price" name="price" required/>
</div>
<div class="form-group">
<label for="quantity">Količina:</label>
<input type="text" class="form-control" id="quantity" name="quantity" required/>
</div>
<div class="form-group">
<label for="quantity">Slika:</label>
<input type="file" class="form-control" id="image" name="image"/>
</div>
<input type="submit" class="btn btn-primary" name="submit" value="Dodaj automobil">
</form>
</div>
<?php
if (isset($_POST['submit'])) {
$name = $_POST["name"];
$year = $_POST["year"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];
$brand_id = intval($_POST["brand"]);
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
if (!move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
$target_file = '';
}
$sql = "INSERT INTO automobil (naziv, godiste, cijena_po_satu, kolicina, putanja_slike, marka_id)
VALUES ("."'". $name."'".","."'". $year."'".","."'". $price."'".","."'". $quantity. "'". "," . "'". $target_file. "'".","."'". $brand_id. "'".")";
$result = $con->query($sql);
if ($result) {
header("Location: automobili.php");
}
}
?>
<?php require('footer.php')?>