hi all,
im creating a form wich wil upload images to a folder and
their names and other details to a database.
im able to do uploading but my delete function is not working, please
can anybody tell me mistake n help me??
image_uploader. php
<?
if(isset($_REQU EST['sub']))
{
//print "<pre>";
//print_r ($_FILES);
$dir_path=$_SER VER['DOCUMENT_ROOT']."/uploadproject/images/".
$_FILES['img1']['name'];
//print $dir_path;
if(move_uploade d_file($_FILES['img1']['tmp_name'],$dir_path))
{
//print "sucessfull ";
}
else
{
//print "error";
}
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$date1=date("Y-m-d H:i:s");
$sql="insert into images(imagenam e,image_type,cr eated_date)
values('".$_FIL ES['img1']['name']."','".$_FIL ES['img1']['type']."','".
$date1."')";
mysql_query($sq l);
print "<font color='blue' size='3'>Image Added sucessfully...</
font>";
}
?>
<form name="frm" action="" method="post" enctype="multip art/form-
data">
<table border="1" align="center">
<tr><td colspan="2" align="center"> Image upload</td></tr>
<tr><td>Choos e An Image</td><td><input type="file" name="img1" /</
td>
</tr><tr><td></td><td><input type="submit" name="sub" value="Add
Image" /> <a href="show_imag es.php" target="_blank" >Show
images</a>
<a href="delete_im ages.php" target="_blank" >Delete images</
a></td>
</table>
</form>
show_images.php
<?
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$rs=mysql_query ("select * from images");
$count=mysql_nu m_rows($rs);
$i=1;
while($row=mysq l_fetch_array($ rs))
{
if($i==1 || $i==4)
{
if($i==4)
{
$i=1;
}
?>
</tr><tr>
<?
}
else
{
//print $i;
}
$i=$i+1;
?>
<td><img width="100" height="100" src="images/<?=
$row['imagename']?>" /></td>
<?
}
?>
</tr>
<tr<td<a href="img_uploa der.php"Back </a</td</tr>
</table>
--------------------------
delete_images.p hp
---some problem with this page
<?php
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
@$id = $_POST["id"];
//@$delete = $_POST["delete"];
if ($id) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$sql = "DELETE FROM images WHERE id='$id'";
mysql_query($sq l);
print "Deleted ". $img1 ." from database";
}
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$sql = "SELECT imagename FROM images";
$result = mysql_query($sq l);
?>
<form method="post" action="show_im ages.php">
Picture: <select name="imagename ">
<?php
while ($row = mysql_fetch_arr ay(($result), MYSQL_ASSOC))
print "<option>" . $row["imagename"];
?>
</select>
<input type="submit" name="delete" value="delete">
</form>
-----------------------------
im creating a form wich wil upload images to a folder and
their names and other details to a database.
im able to do uploading but my delete function is not working, please
can anybody tell me mistake n help me??
image_uploader. php
<?
if(isset($_REQU EST['sub']))
{
//print "<pre>";
//print_r ($_FILES);
$dir_path=$_SER VER['DOCUMENT_ROOT']."/uploadproject/images/".
$_FILES['img1']['name'];
//print $dir_path;
if(move_uploade d_file($_FILES['img1']['tmp_name'],$dir_path))
{
//print "sucessfull ";
}
else
{
//print "error";
}
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$date1=date("Y-m-d H:i:s");
$sql="insert into images(imagenam e,image_type,cr eated_date)
values('".$_FIL ES['img1']['name']."','".$_FIL ES['img1']['type']."','".
$date1."')";
mysql_query($sq l);
print "<font color='blue' size='3'>Image Added sucessfully...</
font>";
}
?>
<form name="frm" action="" method="post" enctype="multip art/form-
data">
<table border="1" align="center">
<tr><td colspan="2" align="center"> Image upload</td></tr>
<tr><td>Choos e An Image</td><td><input type="file" name="img1" /</
td>
</tr><tr><td></td><td><input type="submit" name="sub" value="Add
Image" /> <a href="show_imag es.php" target="_blank" >Show
images</a>
<a href="delete_im ages.php" target="_blank" >Delete images</
a></td>
</table>
</form>
show_images.php
<?
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$rs=mysql_query ("select * from images");
$count=mysql_nu m_rows($rs);
$i=1;
while($row=mysq l_fetch_array($ rs))
{
if($i==1 || $i==4)
{
if($i==4)
{
$i=1;
}
?>
</tr><tr>
<?
}
else
{
//print $i;
}
$i=$i+1;
?>
<td><img width="100" height="100" src="images/<?=
$row['imagename']?>" /></td>
<?
}
?>
</tr>
<tr<td<a href="img_uploa der.php"Back </a</td</tr>
</table>
--------------------------
delete_images.p hp
---some problem with this page
<?php
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
@$id = $_POST["id"];
//@$delete = $_POST["delete"];
if ($id) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$sql = "DELETE FROM images WHERE id='$id'";
mysql_query($sq l);
print "Deleted ". $img1 ." from database";
}
mysql_connect(" localhost","roo t","");
mysql_select_db ("mac");
$sql = "SELECT imagename FROM images";
$result = mysql_query($sq l);
?>
<form method="post" action="show_im ages.php">
Picture: <select name="imagename ">
<?php
while ($row = mysql_fetch_arr ay(($result), MYSQL_ASSOC))
print "<option>" . $row["imagename"];
?>
</select>
<input type="submit" name="delete" value="delete">
</form>
-----------------------------
Comment