php account_edit Sua thong tin PHP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php account_edit Sua thong tin PHP相关的知识,希望对你有一定的参考价值。

<?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>

以上是关于php account_edit Sua thong tin PHP的主要内容,如果未能解决你的问题,请参考以下文章

markdown AWS Cloud Experience Porto Alegre,Transforme sua empresa com Big Data

Deseja sua sorte boa, Renato Augusto

css Semama imagem sai fora da sua div por ser maior isto adapta a div ao tamanho da imagem

数据库主键按照固定前缀生成工具类

Python学习笔记-2017.5.4thon学习笔记-2017.8.08

Python学习笔记-2017.5.4thon学习笔记-2017.8.11