lundi 13 avril 2015

Can't Update Image Src in PHP

I am trying to create a profile picture function for my website. The file upload and image display functions are working properly, however it won't update the "profile" column in my table to the image name. my database name is "intranet" and the table name is "profile"


here is my source code:



<?php session_start();
$_SESSION['username'];
?>

<?php
if(isset($_POST['submit'])){
move_uploaded_file($_FILES['file']['tmp_name'],"images/profile/".$_FILES['file']['name']);
$con = mysqli_connect("localhost","root","","intranet");
$q = mysqli_query($con,"UPDATE user SET profile = '".$_FILES['file']['name']."' WHERE username = '".$_SESSION['username']."'");
}
?>

<!DOCTYPE html>
<html>
<head>

</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit">
</form>


<?php
$con = mysqli_connect("localhost","root","","intranet");
$q = mysqli_query($con,"SELECT * FROM user");
while($row = mysqli_fetch_assoc($q)){
echo $row['Username'];
if($row['profile'] == ""){
echo "<img width='100' height='100' src='images/profile/default.jpg' alt='Default Profile Pic'>";
} else {
echo "<img width='100' height='100' src='images/profile/".$row['image']."' alt='Profile Pic'>";
}
echo "<br>";
}
?>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire