From babb27dd578d3ed131bb5a8d2bc5835e70f57a23 Mon Sep 17 00:00:00 2001 From: valedmar Date: Sun, 13 Apr 2025 13:18:13 +0200 Subject: [PATCH] made some changes --- connect.php | 6 ++--- displayUserDetails.php | 56 +++++++++++++++++++++++++++++++++++------- handleInput.php | 50 ++++++++++++++++++++++++++----------- index.php | 19 ++++++-------- 4 files changed, 92 insertions(+), 39 deletions(-) diff --git a/connect.php b/connect.php index 1c1750b..fafb1e7 100644 --- a/connect.php +++ b/connect.php @@ -1,9 +1,9 @@ '; + echo 'User
'; + echo 'Pass
'; + echo ''; + echo ''; + die(); + } +} + include("connect.php"); ?> @@ -8,7 +29,7 @@ - Assignment + Billeder @@ -24,7 +45,25 @@
-

User Details

+

Uploadede billeder

+
+ +
+ '.$total.' billeder!'; + ?>
@@ -33,15 +72,15 @@ ID Name - Description - Photo + Amount + Last photo ' . $id . ' ' . $name . ' - ' . $description . ' - + ' . $amount . ' - User Photo + Billede '; } diff --git a/handleInput.php b/handleInput.php index 25ac785..25a8299 100644 --- a/handleInput.php +++ b/handleInput.php @@ -7,30 +7,50 @@ if (isset($_POST["submit"])) { // Retrieve user input from the form - $name = $_POST["name"]; - $description = $_POST["description"]; + if ($_POST["name"] = '') { + $name = $_POST["name"]; + } else { + $name = 'n/a'; + } + // deleted the desc. + // $description = $_POST["description"]; + + $files = array_filter($_FILES['photo']['name']); //something like that to be used before processing files. + + // Count # of uploaded files in array + $total = count($_FILES['photo']['name']); + + // Loop through each file + for( $i=0 ; $i < $total ; $i++ ) { + + //Get the temp file path + $tmpFilePath = $_FILES['photo']['tmp_name'][$i]; + + //Make sure we have a file path + if ($tmpFilePath != ""){ + //Setup our new file path + $newName = rand(10000, 99999).'-'. $_FILES['photo']['name'][$i]; + $newFilePath = "./uploads/" . $newName; + + //Upload the file into the temp dir + if(move_uploaded_file($tmpFilePath, $newFilePath)) { + // Insert user data into the database + $sql = "INSERT INTO `user` (`name`, `amount`, `photo`) VALUES ('$name', '1', '$newName')"; + $result = mysqli_query($conn, $sql); + } + } + } - // File upload handling - $photo = $_FILES['photo']['name']; // Get the original name of the uploaded file - $temp_name = $_FILES['photo']['tmp_name']; // Get the temporary name assigned to the file by the server - $folder = "uploads/"; // Set the folder where uploaded files will be stored - // Move the uploaded file from the temporary location to the specified folder - move_uploaded_file($temp_name, $folder . $photo); - // Insert user data into the database - $sql = "INSERT INTO `user` (`name`, `description`, `photo`) VALUES ('$name', '$description', '$photo')"; - $result = mysqli_query($conn, $sql); // Check if the database insertion was successful if ($result) { // Redirect to a page displaying user details upon success - header("location: displayUserDetails.php"); + header("location: index.php"); + } else { // Print an error message if the database insertion fails echo "Error: " . mysqli_error($conn); } } - -// You can also write the above code in index.php -// Just remove action="handleInput.php" and give it blank like action="" diff --git a/index.php b/index.php index b07e8a2..d953979 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ - Assignment + Billeder @@ -20,7 +20,7 @@
-

Input Details

+

Upload jeres billeder!

@@ -29,26 +29,21 @@
- +
- -
- - -
-
- + - + +
- +