FOXIT
-
Posts
7 -
Joined
-
Last visited
Posts posted by FOXIT
-
-
i have recoded my page to make the uploaded image save also in the database rather than just in path folder with a renamed file of student id. And it went great the only problem left is in displaying it. Here is my student_home.php
<?php $query = "SELECT image FROM student_information WHERE student_id='{$_SESSION['user_id']}'"; $result_array = mysqli_fetch_assoc(mysqli_query($link_id, $query)); $actual_image_name = $result_array['image']; ?> <div id="about-img"> <img class="profile-photo" align="middle" src='uploads/".$actual_image_name."' /> </div>
The image wont display using the variable
$actual_image_name
but will display using directly the filename, example
src="uploads/125.jpg"
any idea, would be helpful..
-
thanks mac_gyver found the error by following your suggestion.
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xamppp\htdocs\a\Student_Home.php on line 56
Table 'student.users' doesn't exist -
I have followed your advise. Please take a look on my student_home.php
<?php $query = "SELECT users.profile_image FROM users AS users WHERE student_id='{$_SESSION['user_id']}'"; $result_array = mysqli_fetch_assoc(mysqli_query($link_id, $query)); $actual_image_name = $result_array['profile_image']; ?> <div id="about-img"> <img class="profile-photo" align="middle" src='uploads/".$actual_image_name."' /> </div>
regarding on the definition of link_id. here is my connect.php
<?php $host = "localhost"; $dbusername = "root"; $dbpassword = "765632"; $dbname = "student"; $link_id = mysqli_connect($host,$dbusername,$dbpassword,$dbname) or die("Error " . mysqli_error($link_id)); ?>
I now received a display warning saying
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xamppp\htdocs\a\Student_Home.php on line 56
and the profile image still wont display.
-
@ialso agree: whoahh i am not defining it in Student_Home.php. Do i need to do it? Sorry, can you teach me how to define it.
-
@ialsoagree: On line 22 of ajaximage.php
-
Good Day PHP world,
I am encountering a problem in php code meant to allow the user to update their profile picture.
I am using jquery.min and jquery.js. The code below runs with no errors reported. The file has been successfully uploaded to upload path using this form.
upload.php
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'> <input type="file" name="photoimg" id="photoimg" class="stylesmall"/> </form>
ajaximage.php
$path = "uploads/"; $valid_formats = array("jpg", "png", "gif", "bmp","jpeg"); if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { $name = $_FILES['photoimg']['name']; $size = $_FILES['photoimg']['size']; if(strlen($name)) { list($txt, $ext) = explode(".", $name); if(in_array($ext,$valid_formats)) { if($size<(1024*1024)) // Image size max 1 MB { $actual_image_name = $name.".".$ext; $tmp = $_FILES['photoimg']['tmp_name']; if(move_uploaded_file($tmp, $path.$actual_image_name)) { $query = "UPDATE users SET profile_image='$actual_image_name' WHERE student_id='{$_SESSION['user_id']}'"; $result = mysqli_query($link_id, $query); echo "<img src='uploads/".$actual_image_name."' class='preview'>"; }
The problem is the image being uploaded does not display on the
Student_home.php
<div id="about-img"> <img class="profile-photo" align="middle" src='uploads/".$actual_image_name."' /> </div>
But the image uploaded will display when i write directly its filename example
<div id="about-img"> <img class="profile-photo" align="middle" src="uploads/107.jpg" /> </div>
My problem is i wanted to display the uploaded picture of the specific student on Student_Home.php
how to display user profile image
in PHP Coding Help
Posted
Thank you so much mac_gyver..my long time nightmare has been solved.