PHP Demo
PHP Code
Output
A demo of $_POST with MySQL DB
Select a product
Select a Product
Wheat
Rice
Sugar
Load Product Information
The PHP Code
< ?php //remove space in PHP tag //Getting product name sent by Post method $productname = $_POST['ProductName']; $dbhostname = 'localhost'; $dbusername = 'username'; $dbpassword = 'password'; $conn = mysql_connect($dbhostname, $dbusername, $dbpassword); if(! $conn ) { die('Could not connect: ' . mysql_error()); } //echo 'MySQL Connected successfully'."
"; mysql_select_db("DBName") or die(mysql_error()); //echo "Connected to Database"."
"; $emp_salary = 7000; $emp_id = 3; $sql_statemanet = "select * from tbl_products where Product_Name = '" .$productname ."'"; $rec_select = mysql_query( $sql_statemanet); if(! $rec_select ) { die('Could not retrieve data: ' . mysql_error()); } //Displaying fetched records to HTML table echo "
"; echo "
Product ID
Product
Quality
Quantity
"; // Using mysql_fetch_array() to get the next row until end of table rows while($row = mysql_fetch_array( $rec_select )) { // Print out the contents of each row into a table echo "
"; echo $row['Product_ID']; echo "
"; echo $row['Product_Name']; echo "
"; echo $row['Product_Quality']; echo "
"; echo $row['Product_Quantity']; echo "
"; } mysql_close($conn); ?>
A demo of $_POST with MySQL DB
Select a product
Select a Product
Wheat
Rice
Sugar
Load Product Information