by jeliey Sun Apr 05, 2009 7:42 pm
CREATE TABLE `book` (
`ISBN_num` varchar(50) NOT NULL default '',
`title` varchar(50) NOT NULL default '',
`categories` varchar(30) NOT NULL default '',
`book_author` varchar(50) NOT NULL default '',
`original_price` float NOT NULL default '0',
`sell_price` double NOT NULL default '0',
`start_date` date NOT NULL default '0000-00-00',
`seller_id` varchar(50) NOT NULL default '',
`buyer_id` varchar(50) NOT NULL default '',
`book_id` int(100) NOT NULL auto_increment,
`status` varchar(50) NOT NULL default '',
PRIMARY KEY (`book_id`)
)
CREATE TABLE `seller` (
`seller_id` varchar(50) NOT NULL default '',
`password` varchar(50) NOT NULL default '',
`name` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`phone_num` varchar(12) NOT NULL default '',
`address` text NOT NULL,
PRIMARY KEY (`seller_id`)
)
addbooks.php
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO book (ISBN_num, title, categories, book_author, original_price, sell_price, start_date, seller_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ISBN_num'], "text"),
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['categories'], "text"),
GetSQLValueString($_POST['book_author'], "text"),
GetSQLValueString($_POST['original_price'], "double"),
GetSQLValueString($_POST['sell_price'], "double"),
GetSQLValueString($_POST['start_date'], "date"),
GetSQLValueString($_POST['seller_id'], "text"));
mysql_select_db($database_system, $system);
$Result1 = mysql_query($insertSQL, $system) or die(mysql_error());
$insertGoTo = "viewbooks_seller.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_system, $system);
$query_Recordset1 = sprintf("SELECT seller_id, name FROM seller WHERE seller_id = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $system) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_system, $system);
$query_Recordset2 = "SELECT * FROM book";
$Recordset2 = mysql_query($query_Recordset2, $system) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
<form action="<?php echo $editFormAction; ?>" name="form2" id="form1" method="POST">
<table width="489" border="1">
<tr>
<td><strong>Seller Name </strong></td>
<td><input name="seller_id" type="hidden" id="seller_id" value="<?php echo $row_Recordset1['seller_id']; ?>" />
<?php echo $row_Recordset1['name']; ?></td>
</tr>
<tr>
<td width="122"><strong>ISBN*</strong></td>
<td width="351"><input name="ISBN_num" type="text" id="ISBN_num" size="50" /></td>
</tr>
<tr>
<td><strong>Title*</strong></td>
<td> </td>
</tr>
<tr>
<td><strong>Category*</strong></td>
<td><label>
<select name="categories" id="categories">
<option value="Accounting" selected="selected">Accounting</option>
<option value="Business">Business</option>
<option value="Computer & IT">Computer & IT</option>
<option value="Engineering">Engineering</option>
</select>
<input name="title" type="text" id="title" size="50" />
</label></td>
</tr>
<tr>
<td><strong>Book Author* </strong></td>
<td><label>
<input name="book_author" type="text" id="book_author" />
</label></td>
</tr>
<tr>
<td><strong>Original Price* </strong></td>
<td>RM
<input name="original_price" type="text" id="original_price" /></td>
</tr>
<tr>
<td><strong>Sell Price* </strong></td>
<td>RM
<input name="sell_price" type="text" id="sell_price" /></td>
</tr>
<tr>
<td><strong>Post date </strong></td>
<td><p>
<input name="start_date" type="hidden" id="start_date" value=" <?php $b=time(); print date("Y-m-d",$b);?>" />
<?php
$b = time ();
print date("Y-m-d",$b) . "<br>";
?></p> </td>
</tr>
</table>
<p> </p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" />
</p>
<input type="hidden" name="MM_insert" value="form2">
</form>
viewbooks_seller.php
<?php require_once('Connections/system.php'); ?>
<?php
$colname_Recordset2 = "-1";
if (isset($_POST['categories'])) {
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $_POST['categories'] : addslashes($_POST['categories']);
}
mysql_select_db($database_system, $system);
$query_Recordset2 = sprintf("SELECT * FROM book WHERE categories = '%s'", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $system) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
<table width="447" border="1">
<tr>
<td width="22" height="18"><div align="center"><strong>No.</strong></div></td>
<td width="143"><div align="center"><strong>Book ID </strong></div></td>
<td width="119"><div align="center"><strong>Title</strong></div></td>
<td width="135"><div align="center"><strong>Status</strong></div></td>
</tr>
<?php $count=0 ?>
<?php do { ?>
<tr>
<td><div align="center">
<?php $count=$count+1; echo $count; ?>
</div></td>
<td><div align="center"><?php echo $row_Recordset2['book_id']; ?></div></td>
<td><div align="center"><a href="bookinfo.php?book_id=<?php echo $row_Recordset2['book_id']; ?>"><?php echo $row_Recordset2['title']; ?></a></div></td>
<td><div align="center"><?php echo $row_Recordset2['status']; ?></div></td>
</tr>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
</table>