Poiw

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Delete

<?php
$connection = mysqli_connect('localhost', 'root', '','sales1');
if($connection){
echo "we are connected";
}else{
die("Connection failed: " . mysqli_connect_error($connection));
}
$query = "select * from customer";
$result = mysqli_query($connection,$query);
if(!$result){
die('Query Filed'.mysqli_error($connection));
}
echo '<table class="table table-primary table-striped">';
echo '<tr>';
echo '<th>cust id</th>';
echo '<th>cust fname</th>';
echo '<th>cust lname</th>';
echo '<th>cust address</th>';
echo '<th>cust tel</th>';
echo '<th>cust sex</th>';
echo '<th>cust email</th>';
echo '<th>ลบ</th>';
echo '</tr>';
while($row = mysqli_fetch_array($result)) {
$cid = $row['cust_id'];
$cfname =$row['cust_fname'];
$clname =$row['cust_lname'];
$caddr =$row['cust_address'];
$ctel=$row['cust_tel'];
$csex=$row['cust_sex'];
$cemail=$row['cust_email'];
echo '<tr>';
echo '<td>'.$cid.'</td>';
echo '<td>'.$cfname.'</td>';
echo '<td>'.$clname.'</td>';
echo '<td>'.$caddr.'</td>';
echo '<td>'.$ctel.'</td>';
echo '<td>'.$csex.'</td>';
echo '<td>'.$cemail.'</td>';
echo "<td><a href='delete.php?ID=$row[0]' onclick=\"return confirm(' Do you want
to delete this record?!!!')\" class ='btn btn-danger btn-xs'>ลบ</a></td> ";
echo '</tr>';
}
echo '</table>';

?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF8">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"
integrity="sha384-
JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<title> ลูกค้า</title>
</head>
<body>

</body>
</html>

Delete2

<?php
$connection = mysqli_connect('localhost', 'root', '','sales1');
if($connection){
echo "we are connected";
}else{
die("Connection failed: " . mysqli_connect_error($connection));
}
$cust_id = $_REQUEST["ID"];
//delete section
$sql = "delete from customer where cust_id=$cust_id";
$result = mysqli_query($connection,$sql);
if(!$result){
die('Query Filed'.mysqli_error($connection));
}

//java script show after delete


if($result){
echo "<script type='text/javascript'>";
echo "alert('Delete Successfully');";
echo "window.location = 'db_delete.php'; ";
echo "</script>";
}
else{
echo "<script type='text/javascript'>";
echo "alert('Error back to delete again');";
echo "</script>";
}
?>

Ass6

<?php
//เชื่อมต่อ
$connect = mysqli_connect('localhost','root','','sales');
//เช็ค
if ($connect) {
// echo '<h1>Connected</h1>';
} else {
die("Connection Failed: " . mysqli_connect_error());
}

$query = "SELECT * FROM customer INNER JOIN customer_type ON


customer.cust_type_id = customer_type.cust_type_id;";
$result = mysqli_query($connect,$query);

if (!$result) {
die('Query Failed: ' . mysqli_error($connect));
}
echo '<center><a href="Asgs6_insert.php" class="btn btn-success mt-5">เพิ่มลูกค้า
</a></center>' ;

echo '<table class="table table-warning table-striped">';


echo '<tr>';
echo '<th>รหัสลูกค้า</th>';
echo '<th>ชื่อลูกค้า</th>';
echo '<th>นามสกุลลูกค้า</th>';
echo '<th>เบอร์โทร</th>';
echo '<th>เพศ</th>';
echo '<th>อีเมลล์</th>';
echo '<th>ประเภทลูกค้า</th>';
echo '<th>แก้ไข</th>';
echo '<th>ลบ</th>';
echo '</tr>';

while ($row = mysqli_fetch_array($result)) {


$cust_id = $row['cust_id'];
$cust_fname = $row['cust_fname'];
$cust_lname = $row['cust_lname'];
$cust_addr = $row['cust_address'];
$cust_tel = $row['cust_tel'];
$cust_sex = $row['cust_sex'];
$cust_email = $row['cust_email'];
$cust_type = $row['cust_type_name'];

echo '<tr>';
echo '<td>'.$cust_id.'</td>';
echo '<td>'.$cust_fname.'</td>';
echo '<td>'.$cust_lname.'</td>';
echo '<td>'.$cust_tel.'</td>';
echo '<td>'.$cust_sex.'</td>';
echo '<td>'.$cust_email.'</td>';
echo '<td>'.$cust_type.'</td>';
echo "<td><a class='btn btn-warning' href='Asgs6_edit.php?ID={$row[0]}'>
แก้ไข</a></td>";
echo "<td><a href='Asgs6_delete.php?ID=$row[0]' onclick=\"return confirm('
Do you want to delete this record?!!!')\" class ='btn btn-danger btn-xs'>ลบ
</a></td> ";
echo '</tr>';
}
echo '</table>';
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assignment6</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js
" integrity="sha384-
YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</head>
<body>

</body>
</html>

Ass6 edit

<?php
//เชื่อมต่อ
$connect = mysqli_connect('localhost','root','','sales');
//เช็ค
if ($connect) {
// echo '<h1>Connected</h1>';
} else {
die("Connection Failed: " . mysqli_connect_error());
}

function showData()
{
global $connect;
$query = "SELECT * FROM customer_type";
$result = mysqli_query($connect, $query);

if (!$result) {
die('Query Failed: ' . mysqli_error($connect));
}

while ($row = mysqli_fetch_assoc($result)) {


$cust_type_id = $row['cust_type_id'];
$cust_type_name = $row['cust_type_name'];
echo "<option value='$cust_type_id'> $cust_type_id-
$cust_type_name</option>";
}
}
$cust_id = $_REQUEST["ID"];

$query = "SELECT * FROM customer WHERE cust_id = '$cust_id'";


$result = mysqli_query($connect, $query);
if (!$result) {
die('Query Failed: ' . mysqli_error($connect));
}

$row = mysqli_fetch_assoc($result);

if (isset($_POST['submit'])) {
$cust_fname = $_POST['cust_fname'];
$cust_lname = $_POST['cust_lname'];
$cust_addr = $_POST['cust_addr'];
$cust_tel = $_POST['cust_tel'];
$cust_sex = $_POST['cust_sex'];
$cust_email = $_POST['cust_email'];
$cust_type_id = $_POST['cust_type_id'];

$query = "UPDATE customer SET ";


$query .= "cust_fname = '$cust_fname', cust_lname = '$cust_lname',
cust_address = '$cust_addr', cust_tel = '$cust_tel', cust_sex
='$cust_sex',cust_email = '$cust_email',cust_type_id = '$cust_type_id'";
$query .= " WHERE cust_id = '$cust_id'";
$result = mysqli_query($connect, $query);
if (!$result) {
die('Query Failed' . mysqli_error($connect));
}

header("Location: Asgs6.php");

}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit_info</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js
" integrity="sha384-
YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</head>
<body>
<div style="width: 350px; margin: auto;">
<form method="POST" action="">
<div class="mb-3">
<label for="cust_id" class="form-label">รหัสลูกค้า</label><br>
<input type="text" class="form-label" name="cust_id" id="cust_id"
value="<?php echo $row['cust_id']; ?>" disabled>
</div>
<div class="mb-3">
<label for="cust_fname" class="form-label">ชื่อลูกค้า</label><br>
<input type="text" class="form-label" name="cust_fname" id="cust_fname"
value="<?php echo $row['cust_fname']; ?>">
</div>
<div class="mb-3">
<label for="cust_lname" class="form-label">นามสกุลลูกค้า</label><br>
<input type="text" class="form-label" name="cust_lname" id="cust_lname"
value="<?php echo $row['cust_lname']; ?>">
</div>
<div class="mb-3">
<label for="cust_addr" class="form-label">ที่อยูล่ ูกค้า</label><br>
<input type="text" class="form-label" name="cust_addr" id="cust_addr"
value="<?php echo $row['cust_address']; ?>">
</div>
<div class="mb-3">
<label for="cust_tel" class="form-label">เบอร์โทรลูกค้า</label><br>
<input type="text" class="form-label" name="cust_tel" id="cust_tel"
value="<?php echo $row['cust_tel']; ?>">
</div>
<div class="mb-3">
<label for="cust_sex" class="form-label">เพศลูกค้า</label>
<select name="cust_sex" id="cust_sex" value="<?php echo $row['cust_sex'];
?>">
<option value="Male" <?php if($row['cust_sex'] == 'male') echo
'selected'; ?>>Male</option>
<option value="Female" <?php if($row['cust_sex'] == 'female') echo
'selected'; ?>>Female</option>
</select>
</div>
<div class="mb-3">
<label for="cust_email" class="form-label">Email ลูกค้า</label><br>
<input type="email" class="form-label" name="cust_email" id="cust_email"
value="<?php echo $row['cust_email']; ?>">
</div>
<div class="mb-3">
<label for="cust_type" class="form-label">ประเภทลูกค้า</label>
<select name="cust_type_id" id="cust_type_id">
<?php showData(); ?>
</select>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
<div>
</body>
</html>

Ass6 Delete

<?php
//เชื่อมต่อ
$connect = mysqli_connect('localhost','root','','sales');
//เช็ค
if ($connect) {
// echo '<h1>Connected</h1>';
} else {
die("Connection Failed: " . mysqli_connect_error());
}
$cust_id = $_REQUEST["ID"];

$query = "DELETE FROM customer WHERE cust_id = $cust_id";


$result=mysqli_query($connect,$query);

if($result){
echo "<script type='text/JavaScript'>";
echo "alert('Delete Successfully');";
echo "window.location = 'Asgs6.php'";
echo "</script>";
}else{
echo "<script type='text/javascript'>";
echo "alert('Error back to delete again');";
echo "</script>";
}
?>
Ass6 insert

<?php
//เชื่อมต่อ
$connect = mysqli_connect('localhost','root','','sales');
//เช็ค
if ($connect) {
// echo '<h1>Connected</h1>';
} else {
die("Connection Failed: " . mysqli_connect_error());
}
function showData(){
global $connect;
$query = "SELECT * FROM customer_type";
$result = mysqli_query($connect, $query);

if (!$result) {
die('Query Failed: ' . mysqli_error($connect));
}

while ($row = mysqli_fetch_assoc($result)) {


$cust_type_id = $row['cust_type_id'];
$cust_type_name = $row['cust_type_name'];
echo "<option value='$cust_type_id'> $cust_type_id-
$cust_type_name</option>";
}
}
if (isset($_POST['submit'])) {
$cust_id = $_POST['cust_id'];
$cust_fname = $_POST['cust_fname'];
$cust_lname = $_POST['cust_lname'];
$cust_addr = $_POST['cust_addr'];
$cust_tel = $_POST['cust_tel'];
$cust_sex = $_POST['cust_sex'];
$cust_email = $_POST['cust_email'];
$cust_type_id = $_POST['cust_type_id'];

$connect = mysqli_connect('localhost', 'root', '', 'sales');


$query = "INSERT INTO
customer(cust_id,cust_fname,cust_lname,cust_address,cust_tel
,cust_sex,cust_email,cust_type_id)VALUES('$cust_id','$cust_fname','$cust_lname','
$cust_addr','$cust_tel','$cust_sex','$cust_email','$cust_type_id')";
$result = mysqli_query($connect,$query);
header('Location: Asgs6.php');
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert_info</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js
" integrity="sha384-
YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</head>
<body>
<div style="width: 350px; margin: auto;">
<form method="POST" action="">
<div class="mb-3">
<label for="cust_id" class="form-label">รหัสลูกค้า</label><br>
<input type="text" class="form-label" name="cust_id" id="cust_id">
</div>
<div class="mb-3">
<label for="cust_fname" class="form-label">ชื่อลูกค้า</label><br>
<input type="text" class="form-label" name="cust_fname" id="cust_fname">
</div>
<div class="mb-3">
<label for="cust_lname" class="form-label">นามสกุลลูกค้า</label><br>
<input type="text" class="form-label" name="cust_lname" id="cust_lname">
</div>
<div class="mb-3">
<label for="cust_addr" class="form-label">ที่อยูล่ ูกค้า</label><br>
<input type="text" class="form-label" name="cust_addr" id="cust_addr">
</div>
<div class="mb-3">
<label for="cust_tel" class="form-label">เบอร์โทรลูกค้า</label><br>
<input type="text" class="form-label" name="cust_tel" id="cust_tel">
</div>
<div class="mb-3">
<label for="cust_sex" class="form-label">เพศลูกค้า</label>
<select name="cust_sex" id="cust_sex">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div class="mb-3">
<label for="cust_email" class="form-label">Email ลูกค้า</label><br>
<input type="email" class="form-label" name="cust_email" id="cust_email">
</div>
<div class="mb-3">
<label for="cust_type" class="form-label">ประเภทลูกค้า</label>
<select name="cust_type_id" id="cust_type_id"><br>
<?php showData(); ?>
</select>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
<div>
</body>
</html>

You might also like