trying to upload and delete pictures
Posted: Wed Dec 15, 2004 6:02 pm
I need some help!!!
I’m trying to upload and delete pictures from the database. They are stored and deleted by product ID. Uploads work fine but when I try to delete one of the uploads it doesn’t work properly. After deleting ( uploading as well) the page refreshes itself and shows the results by product ID. If I delete one picture after refreshing I am loosing the product ID. Consequentially, the page doesn’t show the rest of the pictures that belong the that specific product until I hit the back button on the browser.
For the upload I solved this problem by placing in a header location : page.php?id=.$_GET[‘id’]. And the page receives the product ID after it refreshes.
I also tried to do the same sort of step with the problem that I have when I try to delete a product (seems logical to me) but It doesn’t work. I believe that my knowledge in php is not sufficient enough to try and resolve this problem, so I am asking for your help in assisting me in this matter.
This are the error message that I am getting:
Notice: Undefined index: id ( here is for line: 35 delete part )
Here are the codes:
and
Thanks in advance
I’m trying to upload and delete pictures from the database. They are stored and deleted by product ID. Uploads work fine but when I try to delete one of the uploads it doesn’t work properly. After deleting ( uploading as well) the page refreshes itself and shows the results by product ID. If I delete one picture after refreshing I am loosing the product ID. Consequentially, the page doesn’t show the rest of the pictures that belong the that specific product until I hit the back button on the browser.
For the upload I solved this problem by placing in a header location : page.php?id=.$_GET[‘id’]. And the page receives the product ID after it refreshes.
I also tried to do the same sort of step with the problem that I have when I try to delete a product (seems logical to me) but It doesn’t work. I believe that my knowledge in php is not sufficient enough to try and resolve this problem, so I am asking for your help in assisting me in this matter.
This are the error message that I am getting:
Notice: Undefined index: id ( here is for line: 35 delete part )
Here are the codes:
Code: Select all
<?php
if (in_array (strtolower ($file_type), $image_types,$id)) {
$sql = "INSERT INTO image "
. "(image_type, image, image_size, image_name, image_date, id) ";
$sql.= "VALUES (";
$sql.= "'{$file_type}', '{$userfile}', '{$file_size}', "
. "'{$file_name}', NOW(),'{$id}')";
@mysql_query ($sql, $conn);
//Header("Location:".$_SERVER["PHP_SELF"]);
header("location:admin_updatepictures.php?id=".$_GET['id']);
exit();
}
}
}
if(isset($_GET['iid']))
if ($_GET) {
$iid = $_GET['iid'];
$act = $_GET['act'];
switch ($act) {
case 'view':
$sql = "select * from image where image_id=$iid order by id "; //order by id";
$result = mysql_query($sql,$conn);
if (mysql_num_rows ($result)>0){
$row = @mysql_fetch_array($result);
$image_type = $row["image_type"];
$image = $row["image"];
Header("Content-type: $image_type");
print $image;
}
break;
case 'rem':
if(isset($_GET['id']))
$id=$_GET['id'];
$sql = "DELETE FROM image WHERE image_id=$iid order by id";
@mysql_query ($sql, $conn);
//Header("Location:".$_SERVER["PHP_SELF"])
header("location:admin_updatepictures.php?id=".$_GET['id']);
break;
default:
print "<img src="image.php?iid=$iid">";
break;
}
}
?>Code: Select all
<?php
if(isset($_GET['id'])){
$id=$_GET['id'];
$sql = "SELECT * FROM image WHERE image.id = '$id' ORDER BY image_id ASC";
$result = mysql_query ($sql, $conn);
$i=0;
$str='';
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .= "<a href="admin_updatepictures.php?act=view&iid=".$row["image_id"]."">"
. $row["image_name"]."</a> ";
$str .= "[".$row["image_id"]."] ";
$str .= "[".$row["image_size"]."] ";
$str .= "[".$row["id"]."] ";
$str .= "[<a href="admin_updatepictures.php?act=rem&iid=".$row["image_id"]
. "">Remove</a>]<br>";
}
print $str;
}
}
?>