<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Add a Record</TITLE>
</HEAD>
<BODY>
<?
/***************************************************************************
 *			do_addrecord2.php	          	           *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
 *   File Info:		  Add Stocks Record                                *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include("./config.php");
include("./header.inc");
?>
<center><img src=images/computer.gif border=0><font face=verdana size=3 color=navy>  Adding a Record to STOCKS</font></center><br>
<?
$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"]);
}
if ($pid==NULL and $sitem == NULL and $scat == NULL and $spic == NULL and $stock==NULL and $color == NULL and $size==NULL)
{
	echo("<center>Cannot continue adding stocks records - fields are all empty!</center>");
	echo("<center>Go back and add details before continuing to add a new stocks record!</center><br>");
	echo "<center><a href=show_addrecord2.html><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[defaultcategory]Record</font></a></center><br><center><a href=show_addstockcat.php><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[user defined category] Record</font></a></center>";
        include_once("your-footer.inc");
	exit();
}
if ($pid !=NULL and $sitem != NULL and $scat != NULL and $spic != NULL and $stock != NULL and $color != NULL and $size != NULL)
{

}else
{
	
echo("<center>Cannot continue adding stocks records - all fields must contain data!</center>");
	echo("<center>Go back and add details before continuing to add a new stocks record!</center><br>");
	echo "<center><a href=show_addrecord2.html><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[default category] Record</font></a></center><center><a href=show_addstockcat.php><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[user defined category] Record</font></a></center>";
        include_once("your-footer.inc");
	exit();	
}
$baderr = isBadStr($stock);
if ($baderr) 
{
echo("<center>Cannot continue adding stocks records - Stock must contain digits 0-9 & '.'<br></center>");
echo("<center<Go back and add details before continuing to add a new stocks record!</center><br>");
echo "<img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[default category] Record</font></a></center><center><a href=show_addstockcat.php><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[user defined category] Record</font></a></center>";
include_once("your-footer.inc");
exit();	
}
$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 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("<center><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><br>");
       echo("<br><font face=verdana size=2>Already exists in Stocks table!</font><br>");
       echo("<font face=verdana size=2>Press 'Back' button to return to previous menu. </font><br>");
	echo "<img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[default category] Record</font></a></center><center><a href=show_addstockcat.php><img src=images/back-to.gif border=0><font face=verdana size=2>  Back to Add Stocks[user defined category] Record</font></a></center>";
       include("./your-footer.inc");
       exit();
}
$sql = "INSERT INTO $table (pid, sitem, scat, spic,stock,color,size)
	VALUES ('$pid', '$sitem', '$scat', '$spic','$stock','$color','$size')";
//echo($sql);
?>
<?
$sql_result = mysql_query($sql,$conn)
	or die("Couldn't add record.");

if (!$sql_result) {     
	echo "<P>Couldn't add record!";
} else {

echo "<p align=center><font face=verdana size=2>Product Record sucessfully added!</font></p>
<table border =0 width=400>
<tr>
<td valign=top><strong><font face=verdana size=2>Stock ID:</font></strong></td>
<td valign=top>$pid</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Stock Title:</font></strong></td>
<td valign=top>$sitem</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Category:</font></strong></td>
<td valign=top>$scat</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Picture:</font></strong></td>
<td valign=top>$spic</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Stock:</font></strong></td>
<td valign=top>$stock</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Color:</font></strong></td>
<td valign=top>$color</td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Size:</font></strong></td>
<td valign=top>$size</td>
</tr>
</table>
"; 

}
function isBadStr($str)
{
    if(strlen($str)>=1&&strlen($str)<=150){
      $valid_chars = "0123456789";
      for($i=0;$i<strlen($str);$i++){
        if(strchr($valid_chars,substr($str,$i,1))==false) $x++;
      }
      if($x>0) return true;
    }else{
      return true;
    }
}
?>
<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>
<img src=images/line.gif border=0 width=100%><br><br>
<?php include("./your-footer.inc");?>
</BODY>
</HTML>
