why did my image column in phpmyadmin database is not inserting the filename of the image i inserted but instead it displays [BLOB - 10 B]? and when i'm trying to retrieve or display the inserted image, it displays a blank square box and not the image itself.
What I have tried:
i tried to use the .base64 code to retrieve and display the image but same result, still that blank square box appears and not the inserted image:
here's my code (inserting image)
<?php
session_start();
error_reporting( ~E_NOTICE );
$servername = "localhost";
$username = "bctixpmy_blake";
$password = "Ae1IkMMGj6d2";
$dbname = "bctixpmy_luxury_db";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['btnsave']))
{
$agent_id = rand(10,1000);
$fullname = $_POST['full_name'];
$username = $_POST['user_name'];
$useremail = $_POST['user_email'];
$userweb = $_POST['user_web'];
$userpword = $_POST['user_pword'];
$usercpword = $_POST['user_cpword'];
$stat = 'ACTIVE';
$sql = "SELECT * from tbl_brokers WHERE username='$username'";
if ($res = $conn->query($sql)) {
if ($res->fetchColumn() > 0) {
echo '<script language="javascript">';
echo 'alert("That Username already exist!");';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
else if($userpword != $usercpword)
{
echo '<script language="javascript">';
echo 'alert("Password and Confirm Password did not match.");';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
else{
$imgFile = $_FILES['user_image']['name'];
$tmp_dir =$_FILES['user_image']['tmp_name'];
$imgSize =$_FILES['user_image']['size'];
if(empty($imgFile)){
$errMSG = "Please Select Image File for Profile Picture.";
echo '<script language="javascript">';
echo 'alert("'.$errMSG .'");';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
else
{
$upload_dir = 'user_images/';
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif');
$userpic = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions)){
if($imgSize < 5000000) {
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
$errMSG = "Sorry, your file is too large.";
echo '<script language="javascript">';
echo 'alert("'.$errMSG .'");';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
}
else{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
echo '<script language="javascript">';
echo 'alert("'.$errMSG .'");';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
}
if(!isset($errMSG))
{
$stmt = $conn->prepare('INSERT INTO tbl_brokers(agent_id, fullname, username, user_email, website, pword, conf_pword, userPic, filename, Status) VALUES(:agentid, :fullname, :uname, :user_email, :user_web, :user_pword, :user_cpword, :upic, :imgFile, :stat)');
$stmt->bindParam(':agentid',$agent_id);
$stmt->bindParam(':fullname',$fullname);
$stmt->bindParam(':uname',$username);
$stmt->bindParam(':user_email',$useremail);
$stmt->bindParam(':user_web',$userweb);
$stmt->bindParam(':user_pword',$userpword);
$stmt->bindParam(':user_cpword',$usercpword);
$stmt->bindParam(':upic',$userpic);
$stmt->bindParam(':imgFile',$imgFile);
$stmt->bindParam(':stat',$stat);
if($stmt->execute())
{
$successMSG = "New Broker Record has been successfully saved!";
echo '<script language="javascript">';
echo 'alert("'.$successMSG .'");';
echo 'location.href="https://luxury.global/broker-log-in/";';
echo '</script>';
}
else
{
$errMSG = "error while inserting....";
echo '<script language="javascript">';
echo 'alert("Error while saving records...);';
echo 'location.href="https://luxury.global/broker-signup/";';
echo '</script>';
}
}
}
}
}
?>
and also, i cannot retrieve and display the i inserted using the above code,it only displays a blank square box. if you don't mind, can you give me a sample php script to display images from the database? thank you