<?
############### delete category ################
if (($cdelete!="none") and ($cdelete!=""))
{
$sql="DELETE FROM $table_prod WHERE category=\"$cdelete\"";
mysql_query("$sql");
echo "Category $cdelete deleted!<p>";
// echo mysql_errno().": ".mysql_error()."<BR>";
}
############### delete record ################
if ($delrec=="yes")
{$sql="SELECT * FROM $table_info";
$res_usr=mysql_query("$sql");
while ( @$ress=mysql_fetch_array($res_usr))
{
$qqq=${"d".$ress[0]};
if ($qqq=="on") {
$sql="DELETE FROM $table_info WHERE id='$ress[0]'";
mysql_query("$sql");
$sql="DELETE FROM $table_orders WHERE uid='$ress[0]'";
mysql_query("$sql");
//echo mysql_errno().": ".mysql_error()."<BR>";
}
echo "Records deleted!!!<br> ";
}
}
############### end delete record ################
###############edit record #######################
if ($save=="yes")
{if ($category=="") {echo "Category is empty!!!"; exit; }
if ($img_small!=""){
//copy ($img_small,"./img_small.gif");
$filename = $img_small;
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
$fp2=bin2hex($contents);
}
$sql="INSERT INTO $table_prod SET userid='$uid', title='$titles', describes='$describes', category='$category',
firm='$firms', price='$price', image=\"$fp2\"";
echo "<table border='0' width='500' cellspacing=1 cellpading=1 bgcolor='#DDDDEE'>
<tr><td class='menu'>";
if (mysql_query("$sql")) {echo "New record inserted in table!";} else {echo "<br>New record NOT inserted in table!";}
echo mysql_error();
echo "</td></tr></table>";
echo "<table border='0' width='500' cellspacing=1 cellpading=1 bgcolor='#DDDDEE'>
<tr><td width=100 class='menu'>#Id:</td><td class='hd1'><div align=left>$uid</td></tr>
<tr><td class='menu'>Title:</td><td class='hd1'><div align=left>$titles</td></tr>
<tr><td class='menu'>Describe:</td><td class='hd1'><div align=left>$describes</td></tr>
<tr><td class='menu'>Category:</td><td class='hd1'><div align=left>$category</td></tr>
<tr><td class='menu'>Company:</td><td class='hd1'><div align=left>$firms</td></tr>
<tr><td class='menu'>Price:</td><td class='hd1'><div align=left>$price $fbgp</td></tr>
<tr><td class='menu'>Image:</td><td class='hd1'><div align=left><img src='./img_small.gif'> </td></tr>
</table>";
}
########### Delete record from PRODUCTS tables ####################
if (($idfrom!="") and ($to==""))
{
$sql="DELETE FROM $table_prod where (id='$idfrom')";
if (mysql_query("$sql"))
{echo "Record #$idfrom deleted successfully!<br>";}
else
{echo "Record #$idfrom not deleted!<br>";
echo mysql_errno().": ".mysql_error()."<BR>";}
// echo "$idfrom and $to ";
}
########### Delete records from PRODUCTS tables ####################
if (($idfrom!="") and ($to!=""))
{ $all=$to-$idfrom;
if ($all<=0) {echo "$all $to $from Incorrect from -> to field! Program terminated!"; exit; }
for ( $i=$idfrom; $i<=$to; $i++)
{
$sql="DELETE FROM $table_prod where (id='$i')";
if (mysql_query("$sql"))
{;}
else
{echo "Record #$i not deleted!<br>";}
}
echo "Records deleted successfully!<br>";
}
############ edit record from PRODUCT database #######################
if ( $edit<>"" )
{ $sql="SELECT * FROM $table_prod where (id='$edit')";
$res=mysql_query("$sql");
$row=mysql_fetch_row($res);
if ($row[0]=="")
{echo "No record with id# $edit"; exit;}
echo "<table border='0' width='500' cellspacing='1' cellpading=1 bgcolor='#00CCFF'>
<td class='menu'>Edit product database record with id # $edit</td></tr></table>";
echo "<form action='./admin.php' method='POST' enctype=\"multipart/form-data\">
<table border='0' width='500' cellspacing='1' cellpading=1 bgcolor='#00CCFF'>
<td class='menu'>#Id:</td><td class='hd1'><div align=left>$row[0]</td></tr>
<td class='menu'>Code:</td><td class='hd1'><div align=left><input type='text' name='userid' value='$row[1]' size='30'></td></tr>
<td class='menu'>Title:</td><td class='hd1'><div align=left><input type='text' name='titles' size=40 value='$row[2]'></td></tr>
<td class='menu'>Details:</td><td class='hd1'><div align=left><textarea name='describes' cols='50' rows='4'>$row[3]</textarea></td></tr>
<td class='menu'>Category:</td><td class='hd1'><div align=left><input type='text' name='category' size='40' value='$row[4]'></td></tr>
<td class='menu'>Company:</td><td class='hd1'><div align=left><input type='text' name='firms' value='$row[5]' size='30'></td></tr>
<td class='menu'>Price:</td><td class='hd1'><div align=left><input type='text' name='price' value='$row[6]' size='6'></td></tr>
<td class='menu'>Image:</td><td class='hd1'><div align=left>";
if ($row[7]==""){ echo "No image<br>";}
else{
echo "<img src='./img.php?idim=$row[0]' width=200><br>";
}
echo "<input NAME=\"img_small\" type=\"file\" size=\"20\" maxlength=\"50\">
</td>
</tr>
</table><br>
<input type='hidden' name='userided' value='$row[0]'>
<input type='hidden' name='username' value='$admin'>
<input type='hidden' name='password' value='$password'>
<input type='hidden' name='show' value='Y'>
<input type='submit' value='Submit'>
</form>";
}
#################### save edited record PRODUCT ##########
if ( $userided<>"")
{echo "<br>";
if ($img_small<>""){
//copy ($img_small,"./img_small.gif");
$filename = $img_small;
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
$fp2=bin2hex($contents);
$sql="UPDATE $table_prod SET userid='$userid', title='$titles', describes='$describes', category='$category',
firm='$firms', price=$price, image='$fp2' WHERE (id='$userided')";
}
else
{$sql="UPDATE $table_prod SET userid='$userid', title='$titles', describes='$describes', category='$category',
firm='$firms', price=$price WHERE (id='$userided')";
}
echo "<table border=0 width=500><td class='menu'>";
if (mysql_query("$sql"))
{echo "Record $userided UPDATED!";}
else {echo "$sql<br>Field with #id - $userided NOT UPDATED!";}
echo "</td></tr></table>";
echo "<table border='0' width='500' cellspacing=1 cellpading=1 bgcolor='#ECECEC'>
<tr><td class='menu'>#Id:</td><td class='hd1'><div align='left'>$userided</td></tr>
<tr><td class='menu'>Title:</td><td class='hd1'><div align='left'>$titles</td></tr>
<tr><td class='menu'>Details:</td><td class='hd1'><div align='left'>$describes</td></tr>
<tr><td class='menu'>Category:</td><td class='hd1'><div align='left'>$category</td></tr>
<tr><td class='menu'>Company:</td><td class='hd1'><div align='left'>$firms</td></tr>
<tr><td class='menu'>Price:</td><td class='hd1'><div align='left'>$price</td></tr>
<tr><td class='menu'>Image:</td><td class='hd1'><div align='left'><img src='./img.php?idim=$userided'></td></tr>
</table>";
}
################## Add new product form ####################################
if ($add=="Y")
{ echo "<form action='./admin.php' method='POST' enctype=\"multipart/form-data\">
<table border='0' width='500' cellspacing=1 cellpading=1 bgcolor='#ECECEC'>
<td class='menu'>Add new record:</td></tr></table>
<table border='0' width='500' cellspacing=1 cellpading=1 bgcolor='#ECECEC'>
<tr><td class='menu'>Code:</td>
<td class='hd1'><div align=left><input type='text' name='uid' size='8'></td></tr>
<tr><td class='menu'>Title:</td><td class='hd1'><div align=left>
<input type='text' name='titles' size=40></td></tr>
<tr><td class='menu'>Details:</td><td class='hd1'><div align=left><textarea name='describes' rows=4 cols=40></textarea></td></tr>
<tr><td class='menu'>Categoty:</td><td class='hd1'><div align=left>
<input type='text' name='category' size='40'></td></tr>
<tr><td class='menu'>Company:</td><td class='hd1'><div align=left>
<input type='text' name='firms' size='40'></td></tr>
<tr><td class='menu'>Price:</td>
<td class='hd1'><div align=left><input type='text' name='price' size='8'></td></tr>
<tr><td class='menu'>Image:</td>
<td class='hd1'><div align=left><input NAME=\"img_small\" type=\"file\" size=\"20\" maxlength=\"50\">
</td></tr>
</table>
<input type='hidden' name='save' value='yes'>
<input type='hidden' name='username' value='$admin'>
<input type='hidden' name='password' value='$password'>
<input type='submit' value='Submit'>
<input type='hidden' name='show' value='Y'>
</form>";
}
?>