image not displaying in my form in php - javascript

I am having issues displaying image on the website i am developing. It a website that users can change their profile picture, as well as their basic profile information. bellow is my sample code.
profile.php
<?php
$studpix=$row_rsp['pix'];
$propix='<img class=
"profile-user-img img-responsive img-circle" src="...
/Student /imageupload/blank.png"
alt="profile picture">';
if($propix!=NULL)
{
$propix='<img class="profile-user-img
img-responsive img-circle" src="Student/imageupload/'.$studpix.'"
alt="profile picture">';
};
$profile_pic_btn =
' Profile pics';
$avatar_form = '<form id="avatar_form"
enctype="multipart/form-data" method="post" action="photoup.php">';
$avatar_form .= '<h4>Change your picture</h4>';
$avatar_form .= '<input type="file" name="avatar" required>';
$avatar_form .= '<p><input type="submit" value="Upload"></p>';
$avatar_form .= '</form>';
?>
<?php echo $propix?><?
php echo $avatar_form?><?php echo $profile_pic_btn;?>
//other codes goes here
imageupload.php
<?php
if (isset($_FILES["avatar"]["name"]) && $_FILES["avatar"]
["tmp_name"] != ""){
$fileName = $_FILES["avatar"]["name"];
$fileTmpLoc = $_FILES["avatar"]["tmp_name"];
$fileType = $_FILES["avatar"]["type"];
$fileSize = $_FILES["avatar"]["size"];
$fileErrorMsg = $_FILES["avatar"]["error"];
$kaboom = explode(".", $fileName);
$fileExt = end($kaboom);
list($width, $height) = getimagesize($fileTmpLoc);
if($width < 10 || $height < 10){
echo "ERROR: That image has no dimensions";
exit();
}
$db_file_name = rand(100000000000,999999999999).".".$fileExt;
if($fileSize > 1048576) {
echo "ERROR: Your image file was larger than 1mb";
exit();
} else if (!preg_match("/\.(gif|jpg|png)$/i", $fileName) ) {
echo "ERROR: Your image file was not jpg, gif or png type";
exit();
} else if ($fileErrorMsg == 1) {
echo "ERROR: An unknown error occurred";
exit();
}
$sql = "SELECT pix FROM studentdetails WHERE email='%s'";
$query = mysqli_query($myconn, $sql);
$row = mysqli_fetch_row($query);
$avatar = $row[0];
if($avatar != ""){
$picurl = "../Student/imageupload/$avatar";
if (file_exists($picurl)) { unlink($picurl); }
}
$moveResult = move_uploaded_file(
$fileTmpLoc, "../Student /imageupload /$db_file_name");
if ($moveResult != true) {
echo "ERROR: File upload failed";
exit();
}
include_once("../image_resize.php");
$target_file = "../Student/imageupload/$db_file_name";
$resized_file = "../Student/imageupload/$db_file_name";
$wmax = 200;
$hmax = 300;
img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
$sql = "UPDATE studendetails SET pix='%s' WHERE email='%s' LIMIT 1";
$query = mysqli_query($myconn, $sql);
mysqli_close($myconn);
header("location: profile.php");
exit();
}
?>
Your help will be appreciated.

Try to debug your code step by step.
1. Check whether the file gets uploaded correctly and to the correct folder.
2. Check whether the data is updated correctly in the database.
3. Try to open the file by URL directly in the browser.
4. Check whether your HTML code is outputted correctly on the webpage and debug the outputted source code.
5. Make sure that your HTML code works properly.
There may be more steps to take, but this might give you some direction.

Related

PHP Signup from returns to wrong URL instead of index, Database error?

I currently have a loginsystem where a user is able to register and login as a user.
When the user is logged in they should be able to upload a profile image.
The problem that i have is that when i press the Signup button, i gets rediretec to this URL (http://localhost/php51/login.php) Instead of this (http://localhost/php51/index.php).
The thing is that when the user has been registered, then the user should pop up on index.php and show a default profile pic for the user.
Instead i just get a blank page on (http://localhost/php51/login.php).
This is my database with the columns:
I have two tables in my Database called (loginsystem)
the two tables are:
table "profileimg" with the columns (id, status, userid)
and the table "users" with columns (user_email, user_id, user_name, user_password, user_phone, user_zip)
This is my code:
INDEX.php
<?php
session_start();
include_once 'dbh.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
// Check if there is users
$sql = "SELECT * FROM users";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['user_id'];
$sqlImg = "SELECT * FROM profileimg WHERE userid='$id'";
$resultImg = mysqli_query($conn, $sqlImg);
while ($rowImg = mysqli_fetch_assoc($resultImg)) {
echo "<div>";
if($rowImg['status'] == 0) {
echo "<img src='uploads/profile".$id.".jpg'";
} else {
echo "<img src='uploads/profiledefault.jpg'";
}
echo $row['name'];
echo "</div>";
}
}
} else {
echo "No registered users :";
}
//Her checker vi for om man er logget ind,
//og viser herefter upload FORM
if (isset($_SESSION['id'])) {
if ($_SESSION['id'] == 1) {
echo " You are logged in!";
}
//If the user is logged in, we allow the user to upload a profile image
echo "<form action = 'upload.php' method='POST' enctype = 'multipart/form-data'>
<input type = 'file' name = 'file'>
<button type = 'submit' name = 'submit'>UPLOAD FILE</button>
</form>";
} else {
echo " You are not logged in!";
echo "<form action='login.php' method='POST'>
<input type='text' name='name' placeholder='Name'>
<input type='text' name='phone' placeholder='phone'>
<input type='text' name='email' placeholder='email'>
<input type='text' name='zip' placeholder='zip'>
<input type='password' name='password' placeholder='password'>
<button type ='submit' name='submitSignup'>Signup</button>
</form>";
}
?>
<!--We use HTML forms when we want to upload images or files-->
<!--The form HAS to be set as a POST method, and it needs the "enctype" attribute, which specifies that the content we are submitting using the form is a file-->
<p> Login as user </p>
<form action="login.php" method="POST">
<button type="submit" name="submitLogin"> Login </button>
</form>
<p> Logout as user </p>
<form action="logout.php" method="POST">
<button type="submit" name = "submitLogout">Logout</button>
</form>
</body>
</html>
LOUGOUT.php
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
UPLOAD.php
<?php
//First we check if the form has been submitted
if (isset($_POST['submit'])) {
//Then we grab the file using the FILES superglobal
//When we send a file using FILES, we also send all sorts of information regarding the file
$file = $_FILES['file'];
//Here we get the different information from the file, and assign it to a variable, just so we have it for later
//If you use "print_r($file)" you can see the file info in the browser
$fileName = $file['name'];
$fileType = $file['type'];
//The "tmp_name" is the temporary location the file is stored in the browser, while it waits to get uploaded
$fileTempName = $file['tmp_name'];
$fileError = $file['error'];
$fileSize = $file['size'];
//Later we are going to decide the file extensions that we allow to be uploaded
//Here we are getting the extension of the uploaded file
//First we split the file name into name and extension
$fileExt = explode('.', $fileName);
//Then we get the extention
$fileActualExt = strtolower(end($fileExt));
//Here we declare which extentions we want to allow to be uploaded (You can change these to any extention YOU want)
$allowed = array("jpg", "jpeg", "png", "pdf");
//First we check if the extention is allowed on the uploaded file
if (in_array($fileActualExt, $allowed)) {
//Then we check if there was an upload error
if ($fileError === 0) {
//Here we set a limit on the allowed file size (in this case 500mb)
if ($fileSize < 500000) {
//We now need to create a unique ID which we use to replace the name of the uploaded file, before inserting it into our rootfolder
//If we don't do this, we might end up overwriting the file if we upload a file later with the same name
//Here we create a unique ID based on the current time, meaning that no ID is identical. And we add the file extention type behind it.
$fileNameNew = uniqid('', true).".".$fileActualExt;
//Here we define where we want the new file uploaded to
$fileDestination = 'uploads/'.$fileNameNew;
//And finally we upload the file using the following function, to send it from its temporary location to the uploads folder
move_uploaded_file($fileTempName, $fileDestination);
//Going back to the previous page
header("Location: index.php");
}
else {
echo "Your file is too big!";
}
}
else {
echo "There was an error uploading your file, try again!";
}
}
else {
echo "You cannot upload files of this type!";
}
}
SIGNUP.php
<?php
include_once 'dbh.php';
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$zip = $_POST['zip'];
$password = $_POST['password'];
$sql = "INSERT INTO users (name, phone, email, zip, password)
VALUES ('$name', '$phone', '$email', '$zip', '$password')";
mysqli_query($conn, $sql);
$sql = "SELECT * FROM users WHERE name = '$name' AND phone='$phone'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$userid = $row['user_id'];
$sql = "INSERT INTO profileimg (userid, status)
VALUES ('$userid', 1)";
mysqli_query($conn, $sql);
header("Location: index.php");
}
} else {
echo "Error";
}
DBH.PHP
<?php
$conn = mysqli_connect("localhost", "root", "", "loginsystem");
LOGIN.PHP
<?php
session_start();
if (isset($_POST['submitLogin'])) {
$_SESSION['id'] = 1;
header("Location: index.php");
}
In your file index.php you need to change the line
echo "<form action='login.php' method='POST'>
to
echo "<form action='signup.php' method='POST'>
Right now you're sending your signup data to the wrong place

Upload Images as array

I am trying to upload multiple images to a folder and is working properly. I have a problem when i am trying to store the name of images in database. If i upload just one is working. If i upload more than one I get just one name in my database.
Whats the way to upload, making an array with images titles, to my db?
Here is the code:
<div id="maindiv">
<div id="formdiv">
<h4>Upload Image for </h4>
<form enctype="multipart/form-data" action="" method="post">
<p class="alert alert-info">Only JPEG,PNG,JPG Type Image Uploaded. Image Size Should Be Less Than 100KB.</p>
<hr/>
<div id="filediv"><input name="file[]" type="file" id="file"/></div><br/>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
<input type="submit" value="Upload File" name="add_images" id="upload" class="upload"/>
</form>
</div>
And here is my php:
if (isset($_POST['add_images'])) {
$j = 0;
$target_path = "images/";
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
$validextensions = array("jpeg", "jpg", "png");
$ext = explode('.', basename($_FILES['file']['name'][$i]));//store extensions in the variable
$name_of_img = basename($_FILES['file']['name'][$i]);
$target_path = $target_path . $name_of_img;
$j = $j + 1;
if (($_FILES["file"]["size"][$i] < 1000000)
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
print_r($name_of_img);
$query = "UPDATE post SET ";
$query .= "images = '{$name_of_imgs}' ";
$query .= "WHERE post_id = {$the_post_id}";
$update_cruise_img = sqlsrv_query($con, $query);
} else {
echo $j. ').<span id="error">please try again!.</span><br/><br/>';
}
} else {//if file size and file type was incorrect.
echo $j. ').<span id="error">Wrong file Size or Type</span><br/><br/>';
}
}
}
I tried by creating array like this $name_of_imgs = json_encode($_POST['file']);
but is not working
You need to update the post table outside the for loop.
if (isset($_POST['add_images'])) {
$j = 0;
$name_of_imgs = [];
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
$validextensions = array("jpeg", "jpg", "png");
$ext = explode('.', basename($_FILES['file']['name'][$i]));//store extensions in the variable
$name_of_img = basename($_FILES['file']['name'][$i]);
// define target path here so that it won't concat the last value
$target_path = "images/" . $name_of_img;
$j = $j + 1;
if (($_FILES["file"]["size"][$i] < 1000000) && in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
$name_of_imgs[] = $name_of_img;
} else {
echo $j. ').<span id="error">please try again!.</span><br/><br/>';
}
} else {//if file size and file type was incorrect.
echo $j. ').<span id="error">Wrong file Size or Type</span><br/><br/>';
}
}
// update here
$query = "UPDATE post SET ";
$query .= "images = '" . implode(',', $name_of_imgs) . "' ";
$query .= "WHERE post_id = {$the_post_id}";
$update_cruise_img = sqlsrv_query($con, $query);
}
You may consider creating another table for images.
Hello you have run update query in upload file. it's make sure this_post_id in single that's way may be update record in single file name.

PHP Undefined index (caused by jquery file upload)

I've been trying to get a file-upload working for a website I'm working on. I'm doing this outside of a form, and after days of searching I finally found something that fits my method from the answer on this question:
The thing is, as soon as I applied the code to my own script, I got 'Undefined index' errors, and when I removed it, everything went fine.
Here is my code:
HTML
<div class='error-msg'></div>
<input type='text' id='newsitem-message' />
<input type='file' id='newsitem-thumbnail' />
<div class='submit' onclick='newsItem(\"insert\");'>Post news</div>
jQuery
function newsItem(action){
var thumbnail = $('#newsitem-thumbnail')[0].files[0];
var fileReader = new FileReader();
fileReader.readAsText(thumbnail, 'UTF-8');
fileReader.onload = shipOff;
function shipOff(e){
var r = e.target.result;
if(action == "insert"){
$.post("requestPages/newsitems.php", {message:$("#newsitem-message").val(),
thumbnail:thumbnail.name,
action:action,
data:r},
function(result){
console.log(result);
console.log(r); //This freezes my console/inspector window, forcing me to restart the browser-tab
if(result == "succes"){
window.location.reload();
}else{
$(".error-msg").html(result);
}
});
}else if(action == "delete"){
//To be implemented when I get the submit working D:
}
}
}
PHP (Please excuse the mess -needs serious cleaning)
<?php
include("../assets/libs/SQLLib.php");
DB_Connect("test");
echo print_r($_POST);
echo var_dump($_POST);
$message = $_POST['message'];
$action = $_POST['action'];
$thumbnail = $_POST['thumbnail'];
$data = $_POST['data'];
$serverFile = time().$thumbnail;
$fp = fopen('../assets/images/thumbnails/'.$serverFile, 'w');
fwrite($fp, $data);
fclose($fp);
$returnData = array("serverFile" => $serverFile);
echo json_encode($returnData);
if($_POST['message'] != ""){
$canPost = true;
}else{
echo "The message can not be empty.";
}
if($action == "insert" && $canPost){
$sql = "insert into newsitems
(date, message, thumbnail)
values
(NOW(),'".$message."', '".$thumbnail."')";
$result = mysql_query($sql);
if(!$result){
echo "Uh-oh! Something went wrong while posting the news! ".mysql_error();
}else{
echo "succes";
}
}else if($action == "delete"){
$sql = "";
}
?>
Does anybody see what's going wrong here? Or does anyone have an alternative option?
I hope someone can help me out with this issue.
Change it like this:
include("../assets/libs/SQLLib.php");
DB_Connect("test");
print_r($_POST); //Dont echo, what is already echoed
var_dump($_POST); //Dont echo, what is already echoed
$message = !empty($_POST['message'])?$_POST['message']:'';
$action = !empty($_POST['action'])?$_POST['action']:'';
$thumbnail = !empty($_POST['thumbnail'])?$_POST['thumbnail']:'';
$data = !empty($_POST['data'])?$_POST['data']:'';
if(!empty($thumbnail) && !empty($data)){
$serverFile = time().$thumbnail;
$fp = fopen('../assets/images/thumbnails/'.$serverFile, 'w');
fwrite($fp, $data);
fclose($fp);
$returnData = array("serverFile" => $serverFile);
echo json_encode($returnData);
} else {
echo json_encode(array('error'=>'No data and thumbnail assigned'));
}
if($message != ""){
$canPost = true;
}else{
echo "The message can not be empty.";
}
if($action == "insert" && $canPost){
$sql = "insert into newsitems
(date, message, thumbnail)
values
(NOW(),'".$message."', '".$thumbnail."')";
$result = mysql_query($sql);
if(!$result){
echo "Uh-oh! Something went wrong while posting the news! ".mysql_error();
}else{
echo "success";
}
}else if($action == "delete"){
$sql = "";
}
As well you only need to change error reporting level in .htaccess or php in order to prevent warning message to be displayed. In .htaccess:
php_flag error_reporting E_ERROR
If in .php file then
<?php error_reporting(E_RROR); //This displays only Errors, no warning and notices.
Hope you have tried using
isset($_POST) or isset($_POST['message']) if you get "Notice: Undefined index: message".
So in the end I opted out of a full jQuery-upload, and went for something else.
I am now uploading files purely through a PHP call, instead of a jQuery post event, with a small JavaScript check next to it to see if the form is submittable.
The code:
HTML
<div class='error-msg'></div>
<form method='post' action='requestPages/newsitems.php' enctype='multipart/form-data'>
News message
<textarea id='newsitem-message' name='newsitem-message' onchange='checkFormSubmit()'/>
<input type='file' name='newsitem-thumbnail' id='newsitem-thumbnail' />
<input hidden type='text' value='insert' name='newsitem-action'/>
<input class='submit' id='newsitem-submit' type='submit' value='Post news' disabled/>
</form>
PHP
<?php
include("../assets/libs/SQLLib.php");
DB_Connect("test");
var_dump($_FILES);
var_dump($_POST);
$message = $_POST['newsitem-message'];
$action = $_POST['newsitem-action'];
$errors= array();
$hasFile = false;
if($action == "insert"){
echo ($_FILES['newsitem-thumbnail'][0] == UPLOAD_ERR_NO_FILE);
if(isset($_FILES['newsitem-thumbnail']) && $_FILES['newsitem-thumbnail']['error'] != UPLOAD_ERR_NO_FILE){
$file_name = $_FILES['newsitem-thumbnail']['name'];
$file_size =$_FILES['newsitem-thumbnail']['size'];
$file_tmp =$_FILES['newsitem-thumbnail']['tmp_name'];
$file_type=$_FILES['newsitem-thumbnail']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['newsitem-thumbnail']['name'])));
$extensions= array("jpeg","jpg","png");
if(!in_array($file_ext,$extensions)){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
$hasFile = true;
}
if(empty($errors)){
$sql = "insert into newsitems
(date, message, thumbnail)
values
(NOW(),'".$message."', '".$file_name."')";
$result = mysql_query($sql);
if(!$result){
echo "Uh-oh! Something went wrong while posting the news! ".mysql_error();
}else{
if($hasFile){
if(!move_uploaded_file($file_tmp,"../assets/images/thumbnails/".$file_name)){
echo "Moving the file failed!";
}
}
}
}else{
print_r($errors);
}
}else if($action == "delete"){
$sql = "";
}
?>
JavaScript
function checkFormSubmit(){
if($.trim($('#newsitem-message').val()) != ""){
$('#newsitem-submit').prop('disabled', false);
}else{
$('#newsitem-submit').prop('disabled', true);
}
}

generate unique link that runs an images slider with different images

i searched all over the web and i couldn't find an answer, please help me!.
I have an HTML form, like this one:
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="text" name="folder_name" placeholder="Folder name">
<input type="submit" value="Submit">
</form>
Now, upload.php takes number of images and store a link to the folder in MySQL.
Then i call query.php through angularJS $http to retrieve the link to the folder + the images.
Here is query.php:
session_start();
include 'connection.php';
header("Content-Type: application/json; charset=UTF-8");
$folder = $_SESSION["target_folder"];
$query = "SELECT * FROM links WHERE link LIKE '%$folder%'";
$stmt = $db->prepare($query);
$stmt->execute();
$imagesArray = [];
$images = [];
$response = "";
$imageArray = "";
$first_response = "";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$images = unserialize($row["images"]);
$imagesArray = explode(",", $images);
foreach($imagesArray as $image) {
if ($response != "") {$response .= ",";}
$response .= '{"target_folder":"' . $row["link"] . '",';
//$response .= '"ext":"' . $row["ext"] . '",';
$response .= '"billboardNumber":"' . $image . '"}';
}
}
$response ='{"records":['.$response.']}';
echo $response;
Last is the slider in slider.html that retrieves the JSON data from query.php:
$http.get("php/query.php")
.success(function (response) {
$scope.slides = response.records;
});
Most important part, my question :-)
every time i run slider.html it overwrites the old slider.html link and outputs the images from the last JSON call.
how can i run slider.html for a month and still get to the same folder even if i generate another 1000 links to different folder.
i hope that someone will understand me :-)
thank you !!!

How to show images onto browser? it's giving me errors

i've successfully uploaded my image into folder and successfully saved my path into database now as i tried to show pic into browser it's showing error:
Warning: mysql_query() expects parameter 2 to be resource, object given in C:\Users\Raj\PhpstormProjects\image\upload_file.php on line 6
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\Users\Raj\PhpstormProjects\image\upload_file.php on line 7
File name not found in database
here is my code for form:
<?php
// Assigning value about your server to variables for database connection
$hostname_connect= "localhost";
$database_connect= "photo";
$username_connect= "root";
$password_connect= "Bhawanku";
$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
#mysql_select_db($database_connect) or die (mysql_error());
if($_POST)
{
// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
if ($_FILES["file"]["error"] > 0)
{
// if there is error in file uploading
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
// check if file already exit in "images" folder.
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{ //move_uploaded_file function will upload your image. if you want to resize image before uploading see this link http://b2atutorials.blogspot.com/2013/06/how-to-upload-and-resize-image-for.html
if(move_uploaded_file($_FILES["file"]["tmp_name"],"images/" . $_FILES["file"]["name"]))
{
// If file has uploaded successfully, store its name in data base
$query_image = "insert into acc_images (image, status, acc_id) values ('".$_FILES['file']['name']."', 'display','')";
if(mysql_query($query_image))
{
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
}
else
{
echo 'File name not stored in database';
}
}
}
}
}
?>
<html>
<body>
<form action="upload_file.php" method="post"enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
and here is my code for showing pics:
<?php
$con=mysqli_connect("localhost","root","Bhawanku","photo");
// Check connection
$query_image = "SELECT * FROM acc_images";
// This query will show you all images if you want to see only one image pass acc_id='$id' e.g. "SELECT * FROM acc_images acc_id='$id'".
$result = mysql_query($query_image, $con);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo '<img alt="" src="images/'.$row["image"].'">';
}
}
else
{
echo 'File name not found in database';
}
?>
In the second script, you're connecting as mysqli but then using mysql_query, mysql_num_rows and mysql_fetch_array. MySQLi and MySQL aren't interchangeable.
$result = mysqli_query($query_image, $con);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo '<img alt="" src="images/'.$row["image"].'">';
}
}
else
{
echo 'File name not found in database';
}
You should consider changing the first script to MySQLi too, and use prepared statements instead of concatenating variables into the query.
In first row you use mysqli extension, but in all other - mysql.
Try to change:
<?php
$con=mysql_connect("localhost","root","Bhawanku");
mysql_select_db("photo", $con);
// Check connection
$query_image = "SELECT * FROM acc_images";
// This query will show you all images if you want to see only one image pass acc_id='$id' e.g. "SELECT * FROM acc_images acc_id='$id'".
$result = mysql_query($query_image, $con);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo '<img alt="" src="images/'.$row["image"].'">';
}
}
else
{
echo 'File name not found in database';
}
?>

Categories