<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Update a Record</TITLE>
</HEAD>
<BODY>

<?
/***************************************************************************
 *			do_updaterec4.php	                           *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
 *   File Info:		  Update stocks[user-defined]                      *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include("./config.php");
include("./header.inc");
?>
<?
$table = "stocks";
  if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $pid = addslashes($_POST["pid"]);
        $sitem = addslashes($_POST["sitem"]);
        $scat = addslashes($_POST["scat"]);
        $spic = addslashes($_POST["spic"]);
        $stock = addslashes($_POST["stock"]);
        $color = addslashes($_POST["color"]);
        $size = addslashes($_POST["size"]);
}


$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");
$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database...Please press 'Create Database' to create new database.");
echo("<br><img src=images/line.gif border=0 width=100% height=1><font face=verdana size=2>Updating stock record with STOCK ID = ");
echo($pid);
echo("</font><br>");
$done = "FALSE";
$sql = " SELECT pid,sitem,scat,spic,stock,color,size from $table where pid = $pid";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
while($row=mysql_fetch_array($rs))
{
       echo("<font face=verdana size=2>Stock ID: </font>".$row["pid"]); 
       echo(" <br><font face=verdana size=2>Stock Item: </font>".$row["sitem"]);
       echo(" <br><font face=verdana size=2>Category: </font>".$row["scat"]);
       echo(" <br><font face=verdana size=2>Picture: </font>".$row["spic"]);
       echo(" <br><font face=verdana size=2>Stock:  </font>".$row["stock"]);
       echo(" <br><font face=verdana size=2>Color: </font>".$row["color"]);
       echo(" <br><font face=verdana size=2>Size: </font>".$row["size"]."<br>");
       echo("<font face=verdana size=2>Press the 'View Records' menu link to view all stocks records.</font><img src=images/line.gif border=0 width=100% height=1>");
       $done = "OK";
       $sitem=$row["sitem"];
       $scat=$row["scat"];
       $oldscat = $scat;
       $spic=$row["spic"];
       $stock=$row["stock"];
      $color=$row["color"];
     $size=$row["size"];
}

if ($done=="FALSE")
{
	echo("<font face=verdana size=2>Opps...its seems cannot update stock record with STOCK ID = ");
	echo($pid);
	echo "</font><img src=images/line.gif border=0 width=100% height=1><br><br><br><br><br>";
	include_once("./your-footer.inc");
}

$table = "category";
# get all categories
$sql = " SELECT * from $table order by category";
$rst = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
$number = mysql_num_rows($rst);

$form = "<form action=do_updates2.php method=\"POST\">";
$form.= "<input type=\"hidden\" name=\"pid\" value=\"$pid\" size=\"10\">Stock Item:<br>";
$form.= "<input type = \"text\" name=\"sitem\" value=\"$sitem\" size = \"50\"><br>Categories<br>";
$form.= "<select name=\"scat\">";
if ($number == 0)
{
	$form.= "<option value = \"No Category\">-- No Category --</option></select>";
}
else
{
	while ($row = mysql_fetch_array($rst))
	{
		$category = $row["category"];
		if ($category != $scat)
			$form.= "<option value =\"$category\">-- $category --</option>";
		else
			$form.="<option value = \"$category\" selected>-- $category --</option>";
	}
	$form.="</select>";
}
	
$form.= "<br>Picture:<br>";
$form.= "<input type=\"text\" name=\"spic\"";
$form.= "value=\"$spic\" size=\"100\"<br><br>Stock:<br>";
$form.= "<input type=\"text\" name=\"stock\" value=\"$stock\" size=\"10\"><br>";
$form.= "Color:<br><input type=\"text\" name=\"color\" value=\"$color\" size=\"15\"><br>";
$form.= "Size:<br><input type=\"text\" name=\"size\" value=\"$size\" size=\"10\"><br><br>";
$form.= "<input type=\"submit\" value=\"Update Record\"></form>";
echo $form;
?>

<br><font face=verdana size=2 color=navy>To update the stock record, update the fields and then press 'Update Record' to update the stock record '<?php echo "$pid"?>'</font><br><br>
<center>
<table width="500" border=1><tr align="justify" class="subtitle"><td>
  <p align="center">
  <img border="0" src="images/database.GIF" width="24" height="24"><font face=Verdana size=1><a href="./create_db.php">Create database</a>&nbsp;
  <img border="0" src="images/database.GIF" width="24" height="24"></font><a href="./delete_db.php"><font face=Verdana size=1>Delete database</font></a><font face="Verdana" size="1">&nbsp;
  <img border="0" src="images/Records.GIF" width="24" height="24"><a href="./create_menu.php">Create table</a>&nbsp;&nbsp;&nbsp;&nbsp;
  <img border="0" src="images/Records.GIF" width="24" height="24">&nbsp;
  </font> <a href="./add_menu.php"><font face=Verdana size=1>Add Record </font></a>  
  </p>
  <p align="center">&nbsp;<font face="Verdana" size="1"><img border="0" src="images/Records.GIF" width="24" height="24"></font><a href="./view_menu.php"><font face=verdana size=1>View Records</font></a>&nbsp;
  <font face="Verdana" size="1">&nbsp;&nbsp;&nbsp;
  <img border="0" src="images/Records.GIF" width="24" height="24"></font><a href="./del_menu.php"><font face=verdana size=1>Delete Record</font></a>
  <font face="Verdana" size="1">&nbsp;&nbsp;&nbsp;
  <img border="0" src="images/Records.GIF" width="24" height="24"></font> <a href="./upd_menu.php"><font face=verdana size=1>Update Record</font></a>&nbsp;
  <img border="0" src="images/home-to.GIF" width="24" height="24"><font face=verdana size=1>&nbsp; <a href="./index.php">Home</a></font>  </a></td></tr></table><br></center>
<?php include("./your-footer.inc");?>
</BODY>
</HTML>
