Produce the PHP script needed to access the 5 products (name, prod_number, price
ID: 3720858 • Letter: P
Question
Produce the PHP script needed to access the 5 products (name, prod_number, price) from a My SQL database.
Here is the MySQL Database Code. Please help in accessing this using a PHP Script.
If question requires more criteria, please ask below for additional information.
///////////////////////////////////////////////////////////// MySQL Code /////////////////////////////////////////////////////
CREATE DATABASE products;
CREATE TABLE ProductDetail(
number INT(6) UNSIGNED,
name VARCHAR(30) NOT NULL,
price INT(6) UNSIGNED);
INSERT INTO ProductDetail(number, name, price) VALUES (1, 'Product1', 10);
INSERT INTO ProductDetail(number, name, price) VALUES (2, 'Product2', 10);
INSERT INTO ProductDetail(number, name, price) VALUES (3, 'Product3', 10);
INSERT INTO ProductDetail(number, name, price) VALUES (4, 'Product4', 10);
INSERT INTO ProductDetail(number, name, price) VALUES (5, 'Product5', 10);
Explanation / Answer
<?php
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $con )
{
die('Connection Failed: ' . mysql_error());
}
$qry = 'SELECT number,name,price FROM ProductDetail';
mysql_select_db('products');
$result = mysql_query( $qry, $con );
if(! $result )
{
die('Data was not available: ' . mysql_error());
}
while($row = mysql_fetch_assoc($result)) {
echo "Number ID :{$row['number']} <br> ".
"Name : {$row['name']} <br> ".
"Price : {$row['price']} <br> ".
"--------------------------------<br>";
}
mysql_close($con);
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.