Skip to content

Commit d087419

Browse files
author
Younes Ismaili
committed
create error page
1 parent 026b2c3 commit d087419

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

errorPage/add.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Add Element to Database</title>
5+
<link rel="stylesheet" type="text/css" href="styleadd.css">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>Add Element to Database</h1>
10+
<form action="app.php" method="post" enctype="multipart/form-data">
11+
<label for="title">Title:</label>
12+
<input type="text" name="title" required>
13+
14+
<label for="image">Image:</label>
15+
<input type="file" name="image" accept="image/*" required>
16+
17+
<label for="about">About:</label>
18+
<textarea name="about" required></textarea>
19+
20+
<input type="submit" value="Add Element">
21+
</form>
22+
</div>
23+
</body>
24+
</html>

errorPage/app.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// Set up database connection
3+
$servername = "localhost";
4+
$username = "your_username";
5+
$password = "your_password";
6+
$dbname = "your_database_name";
7+
8+
$conn = new mysqli($servername, $username, $password, $dbname);
9+
if ($conn->connect_error) {
10+
die("Connection failed: " . $conn->connect_error);
11+
}
12+
13+
// Get form data
14+
$title = $_POST['title'];
15+
$about = $_POST['about'];
16+
$image = $_FILES['image']['name'];
17+
$temp = $_FILES['image']['tmp_name'];
18+
19+
// Move uploaded image to server
20+
$upload_dir = "uploads/";
21+
$target_file = $upload_dir . basename($image);
22+
move_uploaded_file($temp, $target_file);
23+
24+
// Insert data into database
25+
$sql = "INSERT INTO elements (title, about, image) VALUES ('$title', '$about', '$image')";
26+
27+
if ($conn->query($sql) === TRUE) {
28+
echo "Element added successfully";
29+
} else {
30+
echo "Error adding element: " . $conn->error;
31+
}
32+
33+
$conn->close();
34+
?>

errorPage/indix.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99
<h1>Welcome to my page</h1>
1010
<nav>
1111
<ul>
12-
<li><a href="#">Home</a></li>
13-
<li><a href="#">About</a></li>
14-
<li><a href="#">Contact</a></li>
12+
<li><a href="/Users/yismaili/Desktop/webserv/errorPage/indix.html">Home</a></li>
13+
<li><a href="/Users/yismaili/Desktop/webserv/errorPage/add.html">Add</a></li>
14+
<li><a href="/Users/yismaili/Desktop/webserv/errorPage/404.html">Contact</a></li>
1515
</ul>
1616
</nav>
1717
</header>
1818

1919
<dev>
20-
<img src="https://cdn.intra.42.fr/users/080cb88649236ca06ede61155d2bf3cb/aoumad.jpg" alt="yismaili">
20+
<img src="https://cdn.intra.42.fr/users/080cb88649236ca06ede61155d2bf3cb/aoumad.jpg" alt="aoumad">
2121
<h2>aoumad</h2>
2222
<p>Abderazzak Oumad, a diligent and aspiring student of 1337 School for computer science. With a passion for coding and a thirst
2323
for knowledge, Abderazzak has been honing his programming skills and expanding his understanding of computer science concepts.
2424
He is an individual with a strong work ethic and always strives to improve himself in every way possible.
2525
Abderazzak is a quick learner and has shown excellent problem-solving skills in various programming projects.
2626
With his dedication and commitment to learning, Abderazzak is set to make a significant contribution to the world of computer science.</p>
2727
</dev>
28+
2829
<dev>
2930
<img src="https://cdn.intra.42.fr/users/b627a0f207cc5e0d352a4f7fb7410813/yismaili.jpg" alt="yismaili">
3031
<h2>yismaili</h2>
@@ -36,7 +37,7 @@ <h2>yismaili</h2>
3637
</dev>
3738

3839
<dev>
39-
<img src="https://cdn.intra.42.fr/users/c06c0753f8262f275a233097381d0190/snouae.jpg" alt="yismaili">
40+
<img src="https://cdn.intra.42.fr/users/c06c0753f8262f275a233097381d0190/snouae.jpg" alt="snouae">
4041
<h2>snouae</h2>
4142
<p>Soufiane Nouae, a diligent and aspiring student of 1337 School for computer science. With a passion for coding and a thirst
4243
for knowledge, Soufiane has been honing his programming skills and expanding his understanding of computer science concepts.

errorPage/styleadd.css

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.container {
2+
margin: auto;
3+
width: 50%;
4+
text-align: center;
5+
}
6+
7+
h1 {
8+
margin-bottom: 50px;
9+
}
10+
11+
form {
12+
display: inline-block;
13+
text-align: left;
14+
}
15+
16+
label, input, textarea {
17+
display: block;
18+
margin-bottom: 10px;
19+
}
20+
21+
input[type="submit"] {
22+
margin-top: 20px;
23+
background-color: #4CAF50;
24+
color: white;
25+
padding: 10px;
26+
border: none;
27+
border-radius: 5px;
28+
cursor: pointer;
29+
}

0 commit comments

Comments
 (0)