First of you need to add this line to the top of your form:
- HTML: Select all
<form action="do_update.php" method="post"enctype="multipart/form-data">
Add validatation for your file upload types like so:
- PHP: Select all
$img = 'image/';
//accepted image types
$accepted = array(
$img.'png',
$img.'jpg',
$img.'jpeg',
$img.'gif',
$img.'pjpeg',
$img.'x-png',
$img.'pjpg'
);
$maxSize = 100000;
Encapsulate the post data from your form:
- PHP: Select all
$id = $_SESSION['ID'];
$name = $_POST['Name'];
$surname = $_POST['Surname'];
$address = $_POST['Address'];
bla bla
Lastly work with the photo:
- PHP: Select all
//work with the photo
$worryAboutPhoto = !empty($_FILES['photo']['name']);
if ($worryAboutPhoto)
{
$uploaded = false;
$photo = $_FILES['photo'];
$trash = explode('.', $photo['name']);
$ext = $trash[sizeof($trash) - 1];
$location = 'file_uploads/'.$id.'.'.$ext;
if ($photo['size'] > $maxSize)
{
flash_warning('The filesize is too large (max of '.$maxSize.' bytes)');
}
else if (!in_array($photo['type'], $accepted))
{
flash_warning('File type not accepted');
}
else
{
if (!move_uploaded_file($photo['tmp_name'], $location))
{
flash_warning('Error uploading file. Please try again');
}
else
{
$uploaded = true;
}
}
}
else $uploaded = true;
//create the $params array
$newVals = array(
'detailsID' => $id,
'name' => $name,
'surname' => $surname,
'address' => $address,
'email' => $email,
'phone' => $phone,
'username' => $username,
'password' => $password
);
//see update_fns.php
if ($uploaded)
{
if (updateAcct($newVals))
{
header('Location: accounts.php');
}
}
else
{
echo '<p>One or more errors occurred</p>';
}
Make sure you create & include you upload functions!
Good luck mate! Its easy once you get the hang of it!