0

Hello Guys. I need your help, I dont know why the input of my code like this, I have a database which is upload, then categorize by Personal, Animals, And Natures. When I choose Personal i want to show all image in Personal, but my code doing like this, when i choose personal the last image of categorize by personal should only query, if i have 5 image in Personal the last image is shown by 5 times, What is the wrong for my code, please guys, help me to detrmine. tnx.
here my code in index.php

<html>
<head>
    <title>Upload Images</title>
</head>
<body>
<table align="Center">
<form action = "get.php" method = "POST" enctype = "multipart/form-data">
<tr>
<td>
Select Category:    <select name ="cat">
                        <option>Personal</option>
                        <option>Animals</option>
                        <option>Natures</option>
                    <select></br>
File:<input type = "file" name = "image"><input type = "submit" value = "Upload" />
</form>
</td>
</tr>
</table>
</body>
</html>

Get.php

<?php
error_reporting (E_ALL^E_NOTICE);
mysql_connect("localhost","root","");
mysql_select_db("images");


if(isset($file)){
echo "Please select an image";

}else{
@$file = $_FILES['image']['tmp_name'];
@$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
@$imagename = addslashes($_FILES['image']['tmp_name']);
@$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == False){
echo "This is not an image file";
}else{
if($_POST['cat'] == 'Personal'){
mysql_query("INSERT INTO upload (name,image,category) VALUES('$imagename','$image','Personal')");
echo "Saved!";
}
}if($_POST['cat'] == 'Animals'){
mysql_query("INSERT INTO upload (name,image,category) VALUES('$imagename','$image','Animals')");
echo "Saved!";
}
if($_POST['cat'] == 'Natures'){
mysql_query("INSERT INTO upload (name,image,category) VALUES('$imagename','$image','Natures')");
echo "Saved!";
}
}
header("Location: view.php");

?>

view.php

<html>
<head>
    <title>View Images</title>
</head>
<body>
<table align="Center">

<form method = "POST" enctype = "multipart/form-data">
<tr>
<td>
Select Category:    <select name ="cat">
                        <option>Personal</option>
                        <option>Animals</option>
                        <option>Natures</option>
                    <select></br>
<input type = "submit" value = "View Photos" />
</form>
</td>
</tr>
</table>
</body>
</html>  
<?php
mysql_connect("localhost","root","");
mysql_select_db("images");
if (!isset($_POST['submit']))
{

@$file = $_FILES['image']['tmp_name'];
@$category = $_GET['category'];
$sql = mysql_query ("SELECT * from upload WHERE `category`= '$category'");
$result = $sql;
while ($row = mysql_fetch_array($result)){
    $cat = $row['category'];
    echo "<img src = getv.php?category=$cat width='250px' height= '250px' />";

    }
}
?>

and lastly getv.php

<?php
error_reporting (E_ALL^E_NOTICE);
mysql_connect("localhost","root","");
mysql_select_db("images");

if(isset($_GET['category']))
{

    $category = mysql_real_escape_string($_GET['category']);
    $query = mysql_query("SELECT image FROM upload WHERE `category` = '$category'");
    while($row = mysql_fetch_array($query))
    {
        $imageData = $row["image"];
        $name = $row["name"];

    }

    header('Content-type:image/jpeg');
    echo $imageData;
    echo $name;
}


?>

help me guys. thanks in advance.

3
Contributors
2
Replies
17
Views
4 Years
Discussion Span
Last Post by Squidge
0

First check whether the data in the table is OK (maybe you have multiple same inserts).

The query in the getv.php seems to be missing the name field, since you refer to it in the while loop:

$query = mysql_query("SELECT image, name FROM upload WHERE `category` = '$category'");
This topic has been dead for over six months. 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.