<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Updating Record for Reviews</TITLE>
</HEAD>
<BODY>

<?php
/***************************************************************************
 *			upd_review.php                                     *
 *                     	          				           *
 *   File Info:		  Updating Reviews                                 *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./header.inc");
?>
<center><img src=images/computer.gif border=0><font face=verdana size=3 color=darkred> Viewing Records from REVIEWS table / Updating Record</font></center><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("./config.php");
include("./tests.php");
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $dispname= addslashes($_POST["dispname"]);
        $pid = addslashes($_POST["pid"]);
        $pitem = addslashes($_POST["pitem"]);
        $title = addslashes($_POST["title"]);
       $review =addslashes($_POST["review"]);
       $oldname = addslashes($_POST["oldname"]);
       if (strpos($oldname,"%") > 0)
       $dispname = str_replace("%20"," ",$oldname);
	$act = addslashes($_POST["act"]);
	
}
if ($pid == NULL or $dispname == NULL)
{
	echo "<center><img src=images/line.gif border=0 width=600 height=1><br><font face=verdana size=2>Opps...You did not input Review ID or Author Name...Please go back and re-input!</font><br><img src=images/line.gif border=0 width=600 height=1>";
	include_once("./your-footer.inc");
	exit();
}
$table = "reviews";

$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.");
$sql = "SELECT * from $table where pid = $pid and dispname = '$dispname'";
$result = mysql_query($sql,$conn);
$done = "FALSE";
while ($row = mysql_fetch_array($result))
{
	$titles = $row["title"];
	$pitems = $row["pitem"];
	$reviews = $row["review"];
	$ratings = $row["rating"];
	$done = "OK";
}

if ($done == "FALSE")
{
	echo "<center><img src=images/line.gif border=0 width=600 height=1><br><font face=verdana size=2>Opps...Cannot find customer review record for Author = '$dispname' and ID = $pid</font><br><img src=images/line.gif border=0 width=600 height=1></center>";
	include_once("./your-footer.inc");
	exit();
}
	
if ($act == "update")
{
	$dispname = str_replace("%20"," ",$dispname);
	echo "<center><img src=images/line.gif border=0 width=100% height=1><br><font face=verdana size=2>Updating review information for product id = $pid and review by author = '$dispname'</font></center>";
	echo "<br><br><font face=verdana size=2>Product Item:</font> $pitem<br><font face=verdana size=2>Title:</font> $title<br><font face=verdana size=2>Review: </font>$review<br>";
	echo "<font face=verdana size=2>Updating Product Item....</font>";
	$sql1 = "UPDATE $table set pitem = '$pitem' where pid = $pid and dispname = '$dispname'";
	$rs1 = mysql_query($sql1,$conn)
		or die("Unable to update product item for review record....");
	echo "<font face=verdana size=2>Updating Title....</font>";
	$sql2 = "UPDATE $table set title = '$title' where pid = $pid and dispname = '$dispname'";
	$rs2 = mysql_query($sql2,$conn)
		or die("Unable to update title for review record....");
	$sql3 = "UPDATE $table set review = '$review' where pid = $pid and dispname = '$dispname'";
	$rs3 = mysql_query($sql3,$conn)
		or die("Unable to update review for review record....");
	echo "<br><br><center><img src=images/bullets.gif border=0><font face=verdana size=2> Successfully updated review record....</font></center><br><img src=images/line.gif border=0 width=100% height=1>";
}
if ($act == NULL and strlen($title) > 0 )
{
	$oldname = str_replace(" ","%20",$dispname);
	
$form = "<table cellborder = 1 width = 400>";
$form.="<form action = upd_reviews.php method = post>";
$form.="<tr><td><b>Product ID:</b></td><td><input type = text name = pid value = '$pid' size = 10 readonly></td></tr>";
$form.="<tr><td><b>Product Item:</b></td><td><input type = text name = pitem value = '$pitems' size = 50></td></tr>";
$form.="<tr><td><b>Title:</b></td><td><input type = text name = title value = '$titles' size = 50></td></tr>";
$form.="<tr><td><b>Review:</b></td><td><input type = text name = review value ='$reviews' size = 100 maxlength =250></td></tr>";
$form.="<tr><td><b>Author:</b></td><td><input type = text name = dispname value = '$dispname' size = 50 readonly></td></tr>";
$form.="<tr><td><b>Rating:</b></td><td><input type = text name = rating value = '$ratings' size = 20 readonly></td></tr>";
$form.="<input type = hidden name = dispname value = '$dispname'><input type = hidden name = pid value = '$pid'>";
$form.="<input type = hidden name = act value ='update'><input type = hidden name = oldname value = $oldname>";
$form.="<tr><td><input type =submit value ='Update Review'></form></table>";
echo $form;
}
include("./your-footer.inc")
?>

</BODY>
</HTML>