0

hi i have followed a online tutorial to replace photo system on my site and all went well till i attempt to upload photo i get no file selected even if i have just gone on the page but after pressing submit i get a success message and the photo goes to the database and in th euploads folder but it doesnt show on the album page can someone check this out as ive been through tutorial twice and there are no comments about this problem my upload code is

<form enctype="multipart/form-data" method="post"> <?php
    if (isset($_POST['upload'])) {
       $name = $_POST['name'];
       $album_id = $_POST['album'];
       $file = $_FILES['file']['name'];
       $file_type = $_FILES['file']['type'];
       $file_size = $_FILES['file']['size'];
       $file_tmp = $_FILES['file']['tmp_name'];
           $random_name = rand();

       if (empty($name) or empty($file)) {
            echo "  please Fill in all fields ! <br/><br/>";
    } else {

            move_uploaded_file($file_tmp, 'uploads/'.$random_name.'.jpg');
            mysqli_query($mysqli,"INSERT INTO photos VALUES('', '$name', '$album_id', '$random_name.jpg')");

            echo "Photo Uploaded ! <br/><br/>";

}
}
?>
Select Photo</td><td><input type="file" accept="image/jpeg" name="file"/> <input type="submit" name="upload" value="Upload Photo"/>

and my album code is

<?php
    $query = mysqli_query($mysqli,"SELECT `id`, `name` FROM `albums`");
    while($run = mysqli_fetch_array($query)) {
        $album_id = $run['id'];
        $album_name = $run['name'];

        $query1 = mysqli_query($mysqli,"SELECT `url` FROM `photos` WHERE `album_id`='$album'");
        $run1 = mysqli_fetch_array($query1);
        $pic = $run1['url'];
   ?> <a href='view.php?id=<?php echo $album_id; ?>'> <div id='view_box'> <img src='uploads/<?php echo $pic; ?>'/> <br/> <b><?php echo $album_name ?></b> </div> </a> <?php

    }
?>

any help would be much appreicated ty all x

2
Contributors
4
Replies
18
Views
1 Year
Discussion Span
Last Post by janicemurby
0

Have you heard of punctuation? I had to take a few mental breaths while reading that first "story".

Try using NULL instead of '' if the first field in photos is the primary key.

You are also open to SQL injection by placing the input variables directly into the query without sanitizing nor using a prepared statement.

In addition, you are running loads of queries - no need - just run one JOINed query / statement. If you are retrieving every photo (as it seems you are from the code), then do this:

SELECT a.`name`, p.`url` FROM `photos` AS p INNER JOIN `albums` AS a ON p.`album_id`= a.`id`

Just one query and one loop.

0

Sorted it now i tried doing that with both queries and didnt do any difference. So i redone the tutoiral and its now working :)

0

Care to share your code? It may help other people with a similar issue. Thanks.

0

yes sure ill post it in code snippet section because its several long files hun

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.