File test_oop.php
<?php
// connect oop mysqli
$localhost = "localhost"; //localhost server ຈຳລອງຜ່ານ web server Xampp,Appserv
$root = "root"; // root ຂອງການຕິດຕັ້ງ ໃນ web server
$pass = "44@44"; // ລະຫັດຜ່ານທີ່ຕິດຕັ້ງໄວ້ ໃນ web server
$db = "mydatabase"; // database ທີ່ຕ້ອງການຈະຕິດຕໍ່
$con= new mysqli($localhost,$root,$pass,$db); // connection
mysqli_query($con,"set names utf8"); // set ພາສາ ເພື່ອອ່ານພາສາລາວ ໄທ ອື່ນໆ
// check connection or die
// ເມື່ອ Error ຈະຂຶ້ນສະແດງ ຂໍ້ຄວາມຕ່າງໆ ແຕ່ຖ້າຫາກ Connection ສຳເລັດ ສະບໍ່ມີຂໍ້ຄວາມຫຍັງຂຶ້ນ
if($con->connect_errno){
echo $con->connect_error;
exit;
}
// end to connection statement
?>
<html>
<head>
<meta charset="utf-8">
<title>Customer</title>
</head>
<body>
<center>
<br>
<form name="update" method="post" action="update.php">
<?php
$strSQLS = " SELECT * FROM customer WHERE CustomerID = 'C002'";
$query = $con->query($strSQLS);
$row = $query->fetch_assoc();
?>
<h3>Form update</h3>
<table border="1" width="900" cellpadding='0' cellspacing='0'>
<tr>
<td width="450" align="center">ID</td>
<td width="450" align="center"><input type="text" name="CustomerID" id="CustomerID" value="<?php echo $row["CustomerID"]; ?>"><input type="hidden" name="HCustomerID" id="HCustomerID" value="<?php echo $row["CustomerID"]; ?>"></td>
</tr>
<tr>
<td align="center">Name</td>
<td align="center"><input type="text" name="Name" id="Name" value="<?php echo $row["Name"];?>"></td>
</tr>
<tr>
<td align="center">Email</td>
<td align="center"><input type="text" name="Email" id="Email" value="<?php echo $row["Email"]; ?>"></td>
</tr>
<tr>
<td align="center">CountryCode</td>
<td align="center"><input type="text" name="CountryCode" id="CountryCode" value="<?php echo $row["CountryCode"]; ?>"></td>
</tr>
<tr>
<td align="center">Used</td>
<td align="center"><input type="text" name="Used" id="Used" value="<?php echo $row["Used"]; ?>"></td>
</tr>
<tr>
<td align="center">Bath</td>
<td align="center"><input type="text" name="bath" id="bath" value="<?php echo $row["bath"];?>"></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>
<?php $con->close(); ?>
========================================================
Flie update.php
<?php
// connect oop mysqli
$localhost = "localhost"; //localhost server ຈຳລອງຜ່ານ web server Xampp,Appserv
$root = "root"; // root ຂອງການຕິດຕັ້ງ ໃນ web server
$pass = "44@44"; // ລະຫັດຜ່ານທີ່ຕິດຕັ້ງໄວ້ ໃນ web server
$db = "mydatabase"; // database ທີ່ຕ້ອງການຈະຕິດຕໍ່
$con= new mysqli($localhost,$root,$pass,$db); // connection
mysqli_query($con,"set names utf8"); // set ພາສາ ເພື່ອອ່ານພາສາລາວ ໄທ ອື່ນໆ
// check connection or die
// ເມື່ອ Error ຈະຂຶ້ນສະແດງ ຂໍ້ຄວາມຕ່າງໆ ແຕ່ຖ້າຫາກ Connection ສຳເລັດ ສະບໍ່ມີຂໍ້ຄວາມຫຍັງຂຶ້ນ
if($con->connect_errno){
echo $con->connect_error;
exit;
}
// end to connection statement
?>
<html>
<head>
<meta charset="utf-8">
<title>Customer</title>
</head>
<body>
<?php
if(isset($_POST["update"])){
$update = " UPDATE customer SET
CustomerID = '".$_POST["CustomerID"]."',
Name = '".$_POST["Name"]."',
Email = '".$_POST["Email"]."',
CountryCode = '".$_POST["CountryCode"]."',
Used = '".$_POST["Used"]."',
bath = '".$_POST["bath"]."'
WHERE CustomerID = '".$_POST["HCustomerID"]."' ";
$query = $con->query($update);
if($query){
echo "<script> alert('Update done'); </script>";
echo "<meta http-equiv='refresh'content='0; url=test_oop.php'>";
}
}
?>
</body>
</html>
<?php $con->close(); ?>
=====================================================
Out Put
After Update
ไม่มีความคิดเห็น:
แสดงความคิดเห็น