What's new

Bakit kaya ganito

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
kapag nag reregistered ako edi ok na tapos nmaag lolog in na ko meron picture sya pero kapag nag updated ako ng picture is nawawala na yun picture nya as in walang display..

ito code ko sa registration.php
$image_name = $_FILES['profile-pic']['name'];
$exploded_array = explode('.',$image_name);
$ext = end($exploded_array);


$source_path = $_FILES['profile-pic']['tmp_name'];
$destination_path = "C:/xampp/htdocs/Innerjoin/photo_folder/" . $image_name;

$uploadOk = 1;
if (!file_exists("C:/xampp/htdocs/Innerjoin/photo_folder")) {
mkdir("C:/xampp/htdocs/Innerjoin/photo_folder", 0777, true);
}
if (is_uploaded_file($source_path)) {
if (move_uploaded_file($source_path, $destination_path));

$query = "INSERT INTO registration (payee_name, email_address, username, password, user_type, image) VALUES ('$payee_name', '$email_address', '$username', '$password', '2', '$image_name')";
$result = mysqli_query($con, $query);

echo "<div class='alert alert-success' role='alert'>
A simple success alert—check it out!
</div>";

}

ito naman code ko sa display.php

session_start();
include "../config/config.php";
if(isset($_SESSION['user_id'])){
$user_id = $_SESSION['user_id'];
$_GET_RECORD = mysqli_query($con,"SELECT * FROM registration WHERE user_id = '$user_id' ");
while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {
$user_id = $row_edit['user_id'];
$payee_name = $row_edit['payee_name'];
$email_address = $row_edit['email_address'];
$username = $row_edit['username'];
$password = $row_edit['password'];
$picture = $row_edit['image'];

}
}else {
echo "You must login first! <a href = '../login.php'>Login now! </a>";
}

?>

<img src="../photo_folder/<?php echo $picture; ?>" class="rounded-5 p-1" width= "50px">

ito naman code ko sa updated.php
<?php
if (isset($_POST['update'])){
$user_id =$_POST ['user_id'];
$payee_name = $_POST['fname'];
$email_address = $_POST['email'];
$username = $_POST['nname'];
$password = $_POST['pword'];
$cpword = $_POST['cpword'];
$old_picture = $_POST['old-picture'];
$new_picture = $_FILES['new-profile']['name'];
if($new_picture !==''){
$update_filename = $_FILES['new-profile']['name'];
}
else {
$update_filename = $old_picture;
}
$mysqli_query = "UPDATE registration SET payee_name = '$payee_name', email_address = '$email_address', username = '$username', password = '$password', confirm_password = '$cpword', image = '$update_filename' WHERE user_id = '$user_id'";
$query_run =mysqli_query($con, $mysqli_query);
if ($query_run){
if($_FILES['new-profile']['name'] !==''){
$image_name = $_FILES['new-profile']['name'];
$exploded_array = explode('.',$image_name);
$ext = end($exploded_array);
$source_path = $_FILES['new-profile']['tmp_name'];
$destination_path = "../photo_folder/" . $image_name;

$uploadOk = 1;
if (!file_exists("../photo_folder/")) {
mkdir("../photo_folder/", 0777, true);
}
if (is_uploaded_file($source_path)) {
if (move_uploaded_file($source_path, $destination_path)) {
// File moved successfully
// Rest of your code
} else {
echo "Failed to move the uploaded file.";
}
} else {
echo "File upload failed.";
}





}
}}
?>
 
From your code, it seems like you are trying to upload and display a profile picture for each user in your registration system. However, there are a few issues with your code that may be causing the problem you mentioned.

1. In your registration.php file, you are inserting the image name into the database without the full path. Instead of just storing the image name, you should store the complete path to the image file. Modify your query like this:

PHP:
$query = "INSERT INTO registration (payee_name, email_address, username, password, user_type, image) VALUES ('$payee_name', '$email_address', '$username', '$password', '2', '$destination_path')";

2. In your display.php file, you are using square brackets around the table name in your SQL query. Replace the square brackets with backticks (`) or remove them altogether:

PHP:
$_GET_RECORD = mysqli_query($con, "SELECT * FROM registration WHERE user_id = '$user_id'");

3. In your updated.php file, you have a typo in your SQL query. Change $mysqli_query to $mysqli_query:

PHP:
$query_run = mysqli_query($con, $mysqli_query);

4. Make sure the form in your updated.php file has enctype="multipart/form-data" attribute set. This is required for file uploads. For example:

HTML:
<form method="POST" action="updated.php" enctype="multipart/form-data">

5. Finally, make sure you are passing the correct user_id value in the form when updating the user's information. Also, make sure the user_id is being retrieved correctly in your display.php file.

If you fix these issues and make sure the file paths are correct, the profile picture should be displayed correctly after updating.
 

Similar threads

Back
Top