Last active
June 4, 2018 13:17
-
-
Save gianghl1983/68ef086c4c135f4cb003cc86a068a5e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include ('database/connect.php'); | |
//B1 = check ID | |
//B2= nap lai data | |
//B3= update | |
$errors = []; | |
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0; | |
if ($id == 0) { | |
header('Location: account_qltc.php'); | |
exit; | |
} | |
//Lay thong tin tu database theo id | |
$sql = sprintf("SELECT * FROM accounts WHERE id=%d LIMIT 1", $id); | |
$query = $db_qltc->query($sql); | |
if (!$query) { | |
header('Location: account_qltc.php'); | |
exit; | |
} | |
$account = $query->fetch_array(true);//laays 1 ban ghi??? | |
//cbi du lieu de INSERT | |
if (isset($_POST['submit'])) { | |
if (!isset($_POST['name']) || $_POST['name'] == '') { | |
$errors[] = 'Vui long nhap ten tai khoan'; | |
} else { | |
$name = trim($_POST['name']); | |
} | |
if (!isset($_POST['status']) || $_POST['status'] == '') { | |
$errors[] = 'Vui long chon trang thai'; | |
} else { | |
$status = $_POST['status']; | |
} | |
if (!isset($_POST['type']) || $_POST['type'] == '') { | |
$errors[] = 'Vui long chon loai tai khoan'; | |
} else { | |
$type = $_POST['type']; | |
} | |
$note = isset($_POST['note']) ? $_POST['note'] : ''; | |
if (count($errors) == 0) { | |
// UPDATE TenBang SET column1=value1, column2=value2,...,columnn=valuen WHERE Dieu_Kien; | |
$sql = "UPDATE accounts SET name='$name', status='$status', type='$type', note='$note' WHERE id=$id";//test myPHP | |
$query = $db_qltc->query($sql); | |
if ($query) { | |
header('Location: account_qltc.php'); | |
exit; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Thêm tài khoản mới</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<?php | |
if (count($errors) > 0): | |
for ($i = 0; $i < count($errors); $i++) : | |
?> | |
<p style="color:red"><?php echo $errors[$i];?></p> | |
<?php | |
endfor; | |
endif; | |
?> | |
<form action="" method="POST"> | |
<input type="text" name="name" value="<?php echo $account['name'];?>"><br> | |
<select name="status"> | |
<option value="">Chọn trạng thái</option> | |
<option value="Open" <?php if ($account['status'] == 'Open') :?> selected="selected"<?php endif;?>>Mở</option> | |
<option value="Close" <?php if ($account['status'] == 'Close') :?> selected="selected"<?php endif;?>>Đóng</option> | |
</select><br> | |
<select name="type"> | |
<option value="">Chọn loại tài khoản</option> | |
<option value="TM" <?php if ($account['type'] == 'TM') :?> selected="selected"<?php endif;?>>Tiền mặt</option> | |
<option value="VDT" <?php if ($account['type'] == 'VDT') :?> selected="selected"<?php endif;?>>Ví điện tử</option> | |
<option value="TKNH" <?php if ($account['type'] == 'TKNH') :?> selected="selected"<?php endif;?>>Tài khoản ngân hàng</option> | |
</select><br> | |
<textarea name="note" cols="30" rows="10"><?php echo $account['note'];?></textarea> | |
<input type="hidden" name="user_id" value="1"> | |
<button type="submit" name="submit">Cập nhật</button> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment