
October 1st, 2005, 03:07 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 1
Time spent in forums: 6 m 22 sec
Reputation Power: 0
|
|
|
My E-commerce script
Ok, I need some help with an e-commerce script that I am writing. Here's what it does.
It detects computer systems from the database and then displays them in a dropdown list. Then when you select one system it will then give you a list of products that are compatible with the system. I got the databasing part down alright but I need help witht he php part.
Here's the code:
Code:
<html>
<head>
<title>Configurator</title>
</head>
<body>
<?PHP
//This part of the file contains the info to make a connection to the
database
//Database access information
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'project');
//Make connection and then select database
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not
connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select database: ' .
mysql_error() );
//form to allow user to select a product to view
echo '<div align="center">
<form method="get" action="index.php">
<select name="system">
<option value="NULL">Choose a System:</option>
';
//retrieve and display available systems
$query = 'SELECT * FROM products ORDER BY system ASC';
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
echo '<option value="', $row[0], '">', stripslashes($row[1]), '</option>
';
}
//complete form
echo '</select>
<input type="submit" name="submit" value="GO!">
</form>
</div>
';
//retrieve system info from particular selection if selected
if (isset($_GET['system'])) {
$s = intval($_GET['system']);
//Get system name
$query = "SELECT system FROM products WHERE id=$s";
$result = mysql_query ($query);
list ($system) = mysql_fetch_array ($result, MYSQL_NUM);
echo "<hr /><div align=\"center\"><b>$system Info</b><br />
<small>(All products will open in their own window. Recently added
products will show first.)</small></div>\n";
//initialize variable
$first = TRUE;
//Query the database
$query = "SELECT price, item, description, sku FROM hardware WHERE
system=$s OR system1=$s";
$result = mysql_query ($query);
//display all systems
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
//If this is the first record, create table header
if ($first) {
echo '<table border="1" width="100%" cellspacing="3" cellspacing="3"
align="center">
<tr><td align="left" width="5%"><b>Select</b></td>
<td align="center" width="37.5%"><font size="+1">Item</font></td>
<td align="center" width="37.5%"><font size="+1">Description</font></td>
<td align="right" width="10%"><b>Sku Number</b></td>
<td align="center" width="10%"><b>Price</b></td>
</tr>';
} //end of $first IF
echo " <tr>
<td align=\"left\"><input name=\"select\" type=\"radio\"
value=\"submit\"></td>
<td align=\"center\"><a href=\"http://{$row['item']}\" target=\"_new\">" .
stripslashes($row['item']) . "</a></td>
<td align=\"center\">{$row['description']}</td>
<td align=\"right\">{$row['sku']}</td>
<td align=\"center\">$ {$row['price']}</td>
</tr>\n";
$tax = ($row['price']) * (.08);
$total = ($tax) + ($row['price']);
//one record is returned
$first = FALSE;
}
//If no records where displayed
if ($first) {
echo '<div align="center">There are currently no systems in the
database.</div>';
} else {
echo ' <tr>
<td colspan="4" align="right">
<b>Tax: <b></td>
<td align="right">$' . number_format ($tax, 2) . '</td>
<br>
<tr>
<td colspan="4" align="right">
<b>Total: <b></td>
<td align="right">$' . number_format ($total, 2) . '</td></table>';
//closes table
}
}
mysql_close(); //close database connection
?>
</body>
</html>
now I integrated code to have a radio selection button next to each item that is detected in the system but I really need help integrating a submit button that will select that item that is selected by the radio button and update the price according to the one I selected, can someone please help me?
|