Write A PHP Program To Add Photos and Display Only 5 Images Per Row
Write A PHP Program To Add Photos and Display Only 5 Images Per Row
Write a Php program to add photos and display only 5 images per row.
connect.php:
<?php
try {
$con = mysqli_connect("localhost:3307//", "root", "", "mydbaa");
} catch (Exception $E) {
echo "<script>alert('Some error occured. Try again later');</script>";
}
?>
display.php:
<html>
<head>
<!-- The below lines are for font, so they are optional -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">
<style>
* {
font-family: "Roboto Mono";
}
</style>
</head>
<body>
<h1>~ YOUR PHOTOS ~</h1>
include("connect.php");
$count = 0;
Question 7 1
while ($row = mysqli_fetch_assoc($query)) {
if ($count == 5) {
echo "</tr>";
$count = 0;
}
if ($count == 0)
echo "<tr>";
echo "<td>";
$photo = $row["Location"];
$id = $row["ImageName"];
$d = $row["DateAdded"];
echo $photo;
echo "<td><center>";
$count++;
}
?>
</tr>
</table>
</form>
</body>
</html>
addphoto.php:
<?php
include("connect.php");
if (!isset($_FILES["image"]["tmp_name"])) {
echo "";
} else {
$file = $_FILES["image"]["tmp_name"];
$image_name = $_FILES["image"]["name"];
$size = $_FILES["image"]["size"];
$error = $_FILES["image"]["error"];
if ($error > 0) {
die("Error uploading files");
} else {
if ($size > 10000000) {
die("Fromat is not allowed");
} else {
move_uploaded_file($file, "upload/" . $image_name);
$location = "upload/" . $_FILES["image"]["name"];
$update = mysqli_query($con, "insert into photos values('$location', '$image_name', NOW());");
}
header("location:display.php");
}
}
Question 7 2
?>
Output:
Question 7 3