Hi,
Currently I have a profile page that displays the information from the profile database table and this works fine.
I also have an edit profile page where, if the user provides an about me, location and a profile image, the profile table in the database is updated and is then displayed on their profile page.
The problem I am having is, if the user wanted to only edit, say, their about me and leave their location and profile image the same, it sets the profile table to blank for the inputs that were not filled in by the user (the profile image and then location in this case).
this is my code:
$db = Database::getConnection();
$query = "SELECT * FROM profile WHERE username=:username";
$output = $db->prepare($query);
$output->bindParam(':username', $s_username);
$success = $output->execute();
if ($success){
$row = $output->fetch();
$db_about = $row['about'];
$db_location = $row['location'];
$db_filePath = $row['image'];
$rest = substr("".$db_filePath."", 8);
}}
$uploadDir = 'uploads/';
if(isset($_POST['submit']))
{
$about = $_POST['about'];
$location = $_POST['location'];
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo' An error occurred';
exit();
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$db = Database::getConnection();
$query = "UPDATE profile SET image='$filePath',about='$about',location='$location' WHERE username=:username";
$output = $db->prepare($query);
$output->bindParam(':username', $s_username);
$success = $output->execute();
if($success){
echo 'Upload complete<br><br>';
} else {
echo 'error occurred';
}
}
?>
<form name="editProfile" enctype="multipart/form-data" action="editProfile.php" method="POST">
<textarea id="editProfile" name="about" placeholder="About Me"></textarea><br/>
<input type="text" id="editProfile" name="location" placeholder="Location"><br/>
<div id="profileUpload">
<input type="file" name="Photo" size="2000000" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png" size="26"><br/>
</div>
<!--
<INPUT type="submit" class="button" name="submit" value="Submit">
</form>
I want to be able to update the profile table when only changing one of the inputs. the blank inputs that havent been changed should either:
1. Not update in the SQL,
2. Or get the current info from the profile table and for each input that wasnt updated in editprofile, set the variable as what was in the table before the update, meaning that it is being updated with the same information.