I have developed a registration form using object-oriented techniques, it works fine except when I try and incorportate a file upload so that the user can have a picture saved in the database.
In my database I am using the BLOB format and using file_get_contents to retrieve the file uploaded.
I previously had
$profilepic = $_POST['photo'];
$firstname = $_POST['firstname'];
$firstname = ucfirst($firstname);
$lastname = $_POST['lastname'];
$lastname = ucfirst($lastname);
$user = $_POST['username'];
$user = ucfirst($user);
$pass = $_POST['password'];
$spass = $_POST['secondpassword'];
$profilepic = file_get_contents($_FILES['photo']['tmp_name']);
if($_POST['firstname'] && $_POST['lastname'] && $_POST['photo'] && $_POST['username'] && $_POST['password'] && $_POST['secondpassword'])
if ($spass == $pass)
$query = "INSERT INTO users (firstname, lastname, photo, username, password) VALUES(?, ?, ?, ?, ?)";
$statement = $connection->prepare($query);
$statement->bind_param('ssbss', $firstname, $lastname, $profilepic, $user, $pass);
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
print 'The passwords do not match!';
print 'Enter all fields please';
You can move uploaded image in folder using move_uploaded_file() and store image name in database.
You can get image name as following:
$image_name = $_FILES["photo"]["name"];
For showing image you can retrieve image name.
Then in html you can show image like following: