Skip to content

Commit 7eef915

Browse files
committed
update
1 parent a7a9c69 commit 7eef915

16 files changed

+97
-27
lines changed

databases.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
// reg_date TIMESTAMP
3434
// )";
3535

36+
$sql = "CREATE TABLE LostItems(
37+
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
38+
item_name VARCHAR(30) NOT NULL,
39+
img_name VARCHAR(30) NOT NULL,
40+
reg_date TIMESTAMP
41+
)";
42+
43+
if($conn->query($sql) === TRUE ){
44+
echo "New table 'Items' created successfully!";
45+
} else {
46+
echo "Error: " . $sql . "<br>" . $conn->error ;
47+
}
48+
3649
// insert into database
3750
// $sql = "INSERT INTO MyGuests(firstname, lastname, email)
3851
// VALUES ('Johnny', 'Simple', 'jsimple@gmail.com')";
@@ -62,21 +75,21 @@
6275

6376
// $stmt->close();
6477

65-
$sql = "SELECT id, firstname, lastname FROM MyGuests";
66-
$results = $conn->query($sql);
67-
if($results->num_rows > 0) {
68-
while($row = $results->fetch_assoc()) {
69-
echo "id: " . $row["id"] . " Name: " . $row["firstname"] . " " . $row["lastname"] . "<br>";
70-
}
71-
} else {
72-
echo "0 results";
73-
}
78+
// $sql = "SELECT id, firstname, lastname FROM MyGuests";
79+
// $results = $conn->query($sql);
80+
// if($results->num_rows > 0) {
81+
// while($row = $results->fetch_assoc()) {
82+
// echo "id: " . $row["id"] . " Name: " . $row["firstname"] . " " . $row["lastname"] . "<br>";
83+
// }
84+
// } else {
85+
// echo "0 results";
86+
// }
7487

7588
// deleting data
7689
// $delData = "DELETE FROM MyGuests WHERE id=2";
7790
// $conn->query($delData);
7891

79-
$conn->close();
92+
// $conn->close();
8093

8194
?>
8295

home.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,41 @@
1212

1313
<div class="container">
1414
<?php
15-
$myfile = fopen("imageNames.txt", 'r');
16-
$items = fopen("itemNames.txt", 'r');
17-
while(!feof($myfile) && !feof($items)){
18-
$fname = fgets($myfile);
19-
$iname = fgets($items);
20-
echo "<div class='col-md-3' style='margin-top:50px'>
21-
<img id='imgs' width='200px' height='200px' src='uploads/$fname' />
22-
<h4>$iname</h4>
23-
</div>";
15+
16+
$servername = "localhost";
17+
$username = "root";
18+
$password = "";
19+
$dbname = "myDB";
20+
21+
$conn = new mysqli($servername, $username, $password, $dbname);
22+
23+
$sql = "SELECT * FROM LostItems";
24+
$results = $conn->query($sql);
25+
if($results->num_rows > 0) {
26+
while($row = $results->fetch_assoc()) {
27+
echo "<div class='container'>
28+
<div class='col-md-4'>
29+
<img src='uploads/$row[img_name]' height='200px' width='200px' />
30+
<h4>$row[item_name]</h4>
31+
</div>
32+
</div>";
33+
}
34+
2435
}
25-
fclose($myfile);
36+
$conn->close();
37+
38+
39+
// $myfile = fopen("imageNames.txt", 'r');
40+
// $items = fopen("itemNames.txt", 'r');
41+
// while(!feof($myfile) && !feof($items)){
42+
// $fname = fgets($myfile);
43+
// $iname = fgets($items);
44+
// echo "<div class='col-md-3' style='margin-top:50px'>
45+
// <img id='imgs' width='200px' height='200px' src='uploads/$fname' />
46+
// <h4>$iname</h4>
47+
// </div>";
48+
// }
49+
// fclose($myfile);
2650
?>
2751
</div>
2852

imageNames.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bg.jpg
22
1_83k47hd35h6gmDGwJrZ-Mw.jpeg
33
ball.jpg
4+
s-l225 (4).jpg

itemNames.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Black backpack
22
DroneSpalding
3-
basketball
3+
basketballshoe

upload.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
4+
// connecting to database
5+
$servername = "localhost";
6+
$username = "root";
7+
$password = "";
8+
$dbname = "myDB";
9+
10+
$conn = new mysqli($servername, $username, $password, $dbname);
11+
if($conn->connect_error) {
12+
die("connection failed:" . $conn->connect_error);
13+
}
14+
15+
316
$target_dir = "uploads/";
417
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
518
$uploadOk = 1;
@@ -55,14 +68,33 @@
5568
}
5669
}
5770

58-
$itemFile = fopen("itemNames.txt", 'a');
71+
// $itemFile = fopen("itemNames.txt", 'a');
5972

60-
$imageFile = fopen("imageNames.txt", 'a');
73+
// $imageFile = fopen("imageNames.txt", 'a');
6174
$imgName = $_FILES["fileToUpload"]["name"]."\n";
62-
fwrite($itemFile, $name);
63-
fwrite($imageFile, $imgName);
64-
fclose($itemFile);
65-
fclose($imageFile);
75+
// fwrite($itemFile, $name);
76+
// fwrite($imageFile, $imgName);
77+
// fclose($itemFile);
78+
// fclose($imageFile);
79+
80+
81+
// $sql = "INSERT INTO LostItems(item_name, img_name)
82+
// VALUES ($name, $imgName)";
83+
84+
// if($conn->query($sql) === TRUE) {
85+
// echo "Item added to record successfully!, great work!!";
86+
// } else {
87+
// echo "Lela awu!!!:" . $conn->error;
88+
// }
89+
90+
// preparing and binding
91+
$stmt = $conn->prepare("INSERT INTO LostItems(item_name, img_name) VALUES (?,?)");
92+
$stmt->bind_param("ss", $itemName, $imageName);
93+
94+
// set parameters and execute
95+
$itemName = $name;
96+
$imageName = $imgName;
97+
$stmt->execute();
6698

6799
}
68100

115 KB
Loading
5.14 KB
Loading
6.22 KB
Loading
6.73 KB
Loading
6.88 KB
Loading

0 commit comments

Comments
 (0)