DB Connection
Procedural Connection
<?php
$con = mysqli_connect('localhost', 'root', '', 'clothes');
if($con){
//echo 'Connect';
}
else{echo 'Not Connect';}
?>
PDO
Insert
<?php
$msg = "";
// check if the user has clicked the button "UPLOAD"
if (isset($_POST['uploadfile'])) {
$t1 = $_POST['t1'];
$t2 = $_POST['t2'];
$t3 = $_POST['t3'];
$t4 = $_POST['t4'];
$t5 = $_POST['t5'];
$t6 = $_POST['t6'];
$t7 = $_POST['t7'];
$filename = $_FILES["choosefile"]["name"];
$tempname = $_FILES["choosefile"]["tmp_name"];
$folder = "Image/".$filename;
// connect with the database
// query to insert the submitted data
$sql = "INSERT INTO product (ID, Name, Cat, Detail, Pricein, Priceout, Amount, Picture) VALUES ('$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$filename')";
// function to execute above query
mysqli_query($con, $sql);
// Add the image to the "image" folder"
if (move_uploaded_file($tempname, $folder)) {
//$msg = "Image uploaded successfully";
//echo "<img src=".$folder." height=200 width=300 />";
}else{
$msg = "Failed to upload image";
}
}
?>
Select
<table>
<tr>
<th width="8%">ລະຫັດ</th>
<th width="20%">ຊື່</th>
<th width="8%">ປະເພດ</th>
<th width="20%">ລາຍລະອຽດ</th>
<th width="8%">ລາຄາຊື້</th>
<th width="8%">ລາຄາຂາຍ</th>
<th width="8%">ຈໍານວນ</th>
<th width="8%">ຮູບພາບ</th>
<th colspan="2">ແກ້ໄຂ</th>
</tr>
<?php
$query = " select * from product";
$result = mysqli_query($con, $query);
while ($data = mysqli_fetch_assoc($result)) {
?>
<tr>
<td style="text-align:center;"><?php echo $data['ID'];?></td>
<td style="text-align:center;"><?php echo $data['Name'];?></td>
<td style="text-align:center;"><?php echo $data['Cat'];?></td>
<td style="text-align:center;"><?php echo $data['Detail'];?></td>
<td style="text-align:center;"><?php echo $data['Pricein'];?></td>
<td style="text-align:center;"><?php echo $data['Priceout'];?></td>
<td style="text-align:center;"><?php echo $data['Amount'];?></td>
<td style="text-align:center;"><?php echo $data['Picture'];?></td>
<td width="5%" style="text-align:center;"><a href="Update/UpProduct.php?Edit=<?php echo $data['ID']; ?>">
ແກ້ໄຂ</a></td>
<td style="font-weight:300; text-align:center;" width="5%"><a href="Delete/DelProduct.php?i=<?php echo $data['ID']; ?>">
ລົບ</a></td>
</tr>
<?php
}
//<img src="Image/<?php echo $data['Picture'];
?>
</table>
Update
<?php
$msg = "";
// check if the user has clicked the button "UPLOAD"
if (isset($_POST['update'])) {
$t1 = $_POST['t1'];
$t2 = $_POST['t2'];
$t3 = $_POST['t3'];
$t4 = $_POST['t4'];
$t5 = $_POST['t5'];
$t6 = $_POST['t6'];
$t7 = $_POST['t7'];
$t8 = $_POST['t8'];
$filename = $_FILES["choosefile"]["name"];
$tempname = $_FILES["choosefile"]["tmp_name"];
$folder = "image/".$filename;
if($tempname != "")
{
move_uploaded_file($tempname, $folder);
$update="update product set Name='$t2', Cat='$t3', Detail='$t4', Pricein= '$t5', Priceout= '$t6', Amount= '$t7', Picture= '$filename'
where ID='$t1'";
}else
{
$update="update product set Name='$t2', Cat='$t3', Detail='$t4', Pricein= '$t5', Priceout= '$t6', Amount= '$t7', Picture= '$t8'
where ID='$t1'";
}
$query1=mysqli_query($con, $update);
if($query1){
header("refresh:0; ../Product.php");
}
else{echo'Not Update';}
//echo $pp1, $pp2;
}
?>
More update
<?php
include('DBC.php');
$dd = $_GET['Edit'];
$sql = "select * from subject where ID = '$dd'";
$query = mysqli_query($con, $sql);
if($query){
if($row=mysqli_fetch_assoc($query)){
?>
<div>
<form method="post" enctype="multipart/form-data">
<input type="text" name="u1" value="<?php echo $row['ID']; ?>" >
<input type="text" name="u2" value="<?php echo $row['Name']; ?>" >
<input type="text" name="u3" value="<?php echo $row['Year']; ?>" >
<input type="text" name="u4" value="<?php echo $row['Teacher']; ?>">
<input type="text" name="u5" value="<?php echo $row['Pass']; ?>" >
<input type="submit" name="update" value="ແກ້ໄຂ" id="button">
</form></div>
<?php
try{
if(isset($_POST['update'])){
$pp1=$_POST['u1'];
$pp2=$_POST['u2'];
$pp3=$_POST['u3'];
$pp4=$_POST['u4'];
$pp5=$_POST['u5'];
$sq ="update subject set Name = '$_POST[u2]', Year = '$_POST[u3]', Teacher = '$_POST[u4]', Pass = '$_POST[u5]' where ID = '$pp1' ";
$query = mysqli_query($con, $sq);
if($query){
header("refresh:0; Subject.php");
}
else{echo'Not Update';}
}
}
catch(Exception $ex){}
} }?>
</body>
</html>
Deletet
<?php
include('DBC.php');
if(isset($_GET['i'])) {
$S = $_GET['i'];
$sql1 = "DELETE FROM subject WHERE ID = '$S'";
if(mysqli_query($con, $sql1)){
echo 'Success';
} else {
echo 'Not Delete';
}
}
?>
Select
<table id="recordTable" style="width:90%; margin-left: 5%; border:1px;" cellpadding="5" cellspacing="0">
<thead>
<tr>
<td style="background-color:#9FF; text-align:center; font-size:24px; color:red;" width="5%" align="center">ລະຫັດ</td>
<td style="background-color:#9FF; font-size:24px; color:red;" align="center" width="25%">ຊື່ວິຊາ</td>
<td style="background-color:#9FF; font-size:24px; color:red;" align="center" width="10%">ສົກຮຽນ</td>
<td style="background-color:#9FF; font-size:24px; color:red;" align="center" width="25%">ອາຈານສອນ</td>
<td style="background-color:#9FF; font-size:24px; color:red;" align="center" width="20%">ລະຫັດອາຈານ</td>
<td colspan="2" style="background-color:#9FF; text-align:center; font-size:24px; color:red; width:15%;">ແກ້ໄຂຂໍ້ມູນ</td>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM subject ORDER BY Year ASC";
$query = mysqli_query($con, $sql);
if ($query) {
while ($row_MyRecord = mysqli_fetch_object($query)) { ?>
<tr>
<td style="text-align:center;"><?php echo $row_MyRecord->ID ?></td>
<td><p style="margin-left:10%;"><?php echo $row_MyRecord->Name ?></p></td>
<td style="text-align:center;"><?php echo $row_MyRecord->Year ?></td>
<td style="text-align:center;"><?php echo $row_MyRecord->Teacher ?></td>
<td style="text-align:center;"><?php echo $row_MyRecord->Pass ?></td>
<td width="5%" style="text-align:center;"><a href="Upsubject.php?Edit=<?php echo $row_MyRecord->ID; ?>">ແກ້ໄຂ</a></td>
<td style="font-weight:300; text-align:center;" width="5%"><a href="#" onclick="deleteRecord(event, '<?php echo $row_MyRecord->ID; ?>')">ລົບ</a></td>
</tr>
<?php
}
} ?>
</tbody>
</table>
More select
<input type="submit" onclick="sh();" value="ສະແດງສິນຄ້າ" id="sh">
<input type="submit" onclick="clo();" value="ປິດຟອມສິນຄ້າ" id="clo">
<div id="show">
<table>
<tr>
<th width="8%">ລະຫັດ</th>
<th width="20%">ຊື່</th>
<th width="8%">ປະເພດ</th>
<th width="20%">ລາຍລະອຽດ</th>
<th width="8%">ລາຄາຊື້</th>
<th width="8%">ລາຄາຂາຍ</th>
<th width="8%">ຈໍານວນ</th>
<th width="8%">ຮູບພາບ</th>
<th colspan="2">ແກ້ໄຂ</th>
</tr>
<?php
$query = " select * from product";
$result = mysqli_query($con, $query);
while ($data = mysqli_fetch_assoc($result)) {
?>
<tr>
<td style="text-align:center;"><?php echo $data['ID'];?></td>
<td style="text-align:center;"><?php echo $data['Name'];?></td>
<td style="text-align:center;"><?php echo $data['Cat'];?></td>
<td style="text-align:center;"><?php echo $data['Detail'];?></td>
<td style="text-align:center;"><?php echo $data['Pricein'];?></td>
<td style="text-align:center;"><?php echo $data['Priceout'];?></td>
<td style="text-align:center;"><?php echo $data['Amount'];?></td>
<td style="text-align:center;"><?php echo $data['Picture'];?></td>
<td width="5%" style="text-align:center;"><a href="Update/UpProduct.php?Edit=<?php echo $data['ID']; ?>">
ແກ້ໄຂ</a></td>
<td style="font-weight:300; text-align:center;" width="5%"><a href="Delete/DelProduct.php?i=<?php echo $data['ID']; ?>">
ລົບ</a></td>
</tr>
<?php
}
//<img src="Image/<?php echo $data['Picture'];
?>
</table>
</div>