Hello everyone,
I've been programing cobol for the last 10 years so this is all pretty new to me.
I have some questions on how to structure the code and where to write what in what.
Here's what I want to do:
Basically setting up a very basic an online ordering system. (just for a test program)
(I have a laptop with PHPDEV installed, it runs fine, I have a mysql database on it, php and apache running fine. This is acting as my server)
I want to write a screen that selects data from one mysql table (Products) and shows the contents in a table on the screen, this bit I've done in PHP.
Then next to each row on the table, have an input box "Qty" and a "buy" button.
When "Buy" is clicked, insert a row into the "orders" table, with a unique order num as the primary key and a "product_code" from the display table and the "qty" from the input box on the screen.
what I'm not sure about is where I write what and in what. What do I write in PHP and what in HTML, perhaps all in PHP?
Do I write functions in PHP and call them, I would like to reuse any SQL type code I might write on other screens.
Perhaps someone could explain how to:
- Put a button at the end of each row in the table:
- Write which bit in what
- code up the buy button to pass the value from the table (product_code) and Qty into an insert SQL statement.
Here's what I have so far:
<?php
$pkbutton = "<button><font face = "arial", size = "2">Buy</font></button>";
$db_host = "localhost";
$username = "root";
$password = "";
$db_name = "testglc";
$conn = mysql_connect($db_host, $username, $password);
Mysql_select_db($db_name, $conn) or die("You Thick bastard");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$sql= 'SELECT * FROM testglctab';
$result_set = mysql_query ($sql);
$rows = mysql_NumRows($result_set);
echo "<TABLE borderColor=blue cellSpacing=2 width=100 border=2>";
echo "Parts currently available:";
echo "<TBODY>";
for ($j=0; $j < $rows; $j++) {
echo "<TR>";
echo "<TD>";
echo mysql_result($result_set, $j, "company_name");
echo "</TD>";
echo "<TD>";
echo mysql_result($result_set, $j, "Product_type");
echo "</TD>";
echo "<TD>";
echo mysql_result($result_set, $j, "Product_sub_type");
echo "</TD>";
echo "<TD>";
echo mysql_result($result_set, $j, "Price");
echo "</TD>";
echo "<TD>";
echo mysql_result($result_set, $j, "Num_in_stock");
echo "</TD>";
echo "<TD>";
echo mysql_result($result_set, $j, "Prod_desc");
echo "</TD>";
echo "</TR>";
}
echo "</TBODY>";
echo "</TABLE>";
?>
I don't understand really how PHP and HTML work together.
Thanks a lot anyone for an tips for an old man.
😃
Chedz