Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
4.4 kB
1
Indexable
Never
// model : nguoidung
public function themtaikhoan($taikhoan) {
            $db = DATABASE::connect();
            try{
                $sql = "INSERT INTO taikhoan(email,matkhau,hoten,diachi,sdt,hinhanh,loai_taikhoan) VALUES(:email,:matkhau,:hoten,:diachi,:sdt,:hinhanh,:loai_taikhoan)";
                $cmd = $db->prepare($sql);
                $cmd->bindValue(':email',$taikhoan->email);
                $cmd->bindValue(':matkhau', md5($taikhoan->matkhau));
                $cmd->bindValue(':hoten',$taikhoan->hoten);
                $cmd->bindValue(':diachi',$taikhoan->diachi);
                $cmd->bindValue(':sdt',$taikhoan->sdt);
                $cmd->bindValue(':hinhanh',$taikhoan->hinhanh);
                $cmd->bindValue(':loai_taikhoan',$taikhoan->loai_taikhoan);
                $cmd->execute();
                $id = $db->lastInsertId();
                return $id;
            }
            catch(PDOException $e){
                $error_message=$e->getMessage();
                echo "<p>Lỗi truy vấn: $error_message</p>";
                exit();
            }
        }


// form đăng ký
<div class="card">
                                        <div class="card-body"> 
                                            <div class="m-sm-3">
                                                <form action="index.php" method="post">
                                                    <div class="mb-3">
                                                        <label class="form-label">Email</label>
                                                        <input class="form-control form-control-lg" type="email" name="txtEmail" placeholder="Nhập email"/>
                                                    </div>
                                                    &nbsp;
                                                    <div class="mb-3">
                                                        <label class="form-label">Password</label>
                                                        <input class="form-control form-control-lg" type="password" name="txtPassword" placeholder="Nhập mật khẩu"/>
                                                    </div>
                                                    &nbsp;
                                                    <div class="mb-3">
                                                        <label class="form-label">Họ và tên</label>
                                                        <input class="form-control form-control-lg" type="text" name="txtName" placeholder="Nhập họ và tên người dùng"/>
                                                    </div>
                                                    &nbsp;
                                                    <div class="mb-3">
                                                        <label class="form-label">Số điện thoại</label>
                                                        <input class="form-control form-control-lg" type="number" name="txtPhone" placeholder="Nhập số điện thoại"/>
                                                    </div>
                                                    &nbsp;
                                                    <div class="d-grid gap-2 my-3">
                                                        <input type="hidden" name="action" value="xldangky">
                                                        <input type="submit" class="btn btn-lg btn-info" value="Đăng ký">
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>


// case : xử lý đăng ký
case "xldangky":
                $ndnew = new NGUOIDUNG();
                $ndnew->setemail($_POST["txtEmail"]);
                $ndnew->setmatkhau($_POST["txtPassword"]);
                $ndnew->sethoten($_POST["txtName"]);
                $ndnew->setsdt($_POST["txtPhone"]);
                $ndnew->setdiachi("Null");
                $ndnew->sethinhanh("male.png");
                $ndnew->setloaitaikhoan(0);

                $nd->themtaikhoan($ndnew);
                $tb_user = 1;
                include("module/taikhoan/register.php");
                break;
Leave a Comment