Wednesday, March 2, 2016

sample of Select Product from DB using PHP-MySQL

How to create MSProduct in PHP-MySQL
1. create dbname: product , table : tblproduct , field : id, Pro_name, category, price , Status
2. Configuration config.php
3. how to select some data from tblproduct index.php

config.php
<?php
$server_name="localhost";
$user="root";
$pass="";
$conn=mysql_connect($server_name,$user,$pass);
if(!$conn){
echo "cann't connect to database";
}
echo"success connect";
mysql_select_db("product",$conn);
?>

index.php
<html>
<head>
<?php
include_once('config.php');
$sql="select * from tblproduct";
$query=mysql_query($sql,$conn);
if(!$query){
echo"cann't select data".mysql_error();
}
echo"<table border=1><tr><td>id<td>Product name<td>Category<td>price<td>status</tr>";
while($row=mysql_fetch_array($query)){
$id=$row['id'];
$name=$row['Pro_name'];
$cate=$row['category'];
$price=$row['price'];
$status=$row['Status'];
echo "<tr><td>".$id ."<td>".$name."<td>".$cate.
"<td>".$price."<td>".$status ;
}
echo"</table>"
?>
</head>
<body>
Table of product
</body>
</html>

1 comment: