Hướng dẫn insert data in mysql using php with validation - chèn dữ liệu trong mysql bằng php với xác thực

Lưu trữ chi tiết đăng ký trong bảng MySQL bằng Php

Ở đây chúng tôi sẽ thu thập các chi tiết đăng ký từ thành viên và vượt qua quy trình xác nhận. Thành viên nhập chi tiết đăng ký của anh ấy/cô ấy trong mẫu trong phần I của hướng dẫn.

Hình thức HTML Chèn người dùng đã nhập dữ liệu vào cơ sở dữ liệu và xác thực nếu UserID đã tồn tại.

Đăng phương pháp dữ liệu biểu mẫu

Vì chúng tôi đã sử dụng phương thức đăng dữ liệu, chúng tôi có thể thu thập chúng và sử dụng trong tập lệnh của chúng tôi.

$userid=$_POST['userid'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$agree=$_POST['agree'];
$todo=$_POST['todo'];
$email=$_POST['email'];
$name=$_POST['name'];
$sex=$_POST['sex'];

Trong xác thực, chúng tôi sẽ kiểm tra UserID, địa chỉ email có định dạng chính xác hay không. Chúng tôi cũng sẽ xem liệu userid đã có trong bảng đăng ký vì vậy chúng tôi sẽ yêu cầu thành viên đi cho người dùng khác. Nếu tất cả các thông qua xác thực thì chúng tôi sẽ chèn bản ghi vào bảng và yêu cầu thành viên đăng nhập. Mã mẫu để xác nhận dữ liệu đầu vào biểu mẫu Chúng tôi cũng đã sửa đổi tập lệnh và sử dụng hàm ctype_alnum để kiểm tra userid chỉ để chỉ dữ liệu chữ và số. Bạn có thể sử dụng xác thực của riêng bạn theo yêu cầu. Ý định cơ bản là giải thích cách phát triển tập lệnh đăng ký. Chúng tôi đã kiểm tra rằng userid là tối thiểu 3 char.
Sample codes to validate form input data
Also we have modified the script and using ctype_alnum function to check the userid for alphanumeric data only. You can use your own validation as per requirement. The basic intention is to explain how a signup script is to be developed. We have checked that userid is minimum 3 char length.

$status = "OK";
$msg="";
// if userid is less than 3 char then status is not ok
if[!isset[$userid] or strlen[$userid] prepare["select userid from plus_signup where userid=:userid"];
$count->bindParam[":userid",$userid];
$count->execute[];
$no=$count->rowCount[];

if[$no >0 ]{
$msg=$msg."User Name already exists. Choose a different User Name
"; $status= "NOTOK"; } //Check of email address is already there $count=$dbo->prepare["select email from plus_signup where email=:email"]; $count->bindParam[":email",$email]; $count->execute[]; $no=$count->rowCount[]; if[$no >0 ]{ $msg=$msg."This email address is there with us. If you forgot your password you can activate it by using forgot password link. Or Please try another one
"; $status= "NOTOK"; } if [ strlen[$password] < 3 ]{ $msg=$msg."Password must be more than 3 char legth
"; $status= "NOTOK";} if [ $password $password2 ]{ $msg=$msg."Both passwords are not matching
"; $status= "NOTOK";} if [$agree"yes"] { $msg=$msg."You must agree to terms and conditions
"; $status= "NOTOK";}

Thêm bản ghi vào bảng cơ sở dữ liệu

Nếu tất cả các xác nhận được thông qua thì chúng tôi sẽ thêm dữ liệu của chúng tôi vào một bản ghi trong bảng. Chúng tôi cũng sẽ gửi một tin nhắn chào mừng với người dùng và mật khẩu cho thành viên. Đây là lệnh chèn.

if[$status"OK"]{ 
echo "$msg
"; }else{ // if all validations are passed. $password_original = $password; $password=md5[$password]; // Encrypt the password before storing $sql=$dbo->prepare["insert into plus_signup[userid,password,email,name,sex] values[:userid,:password,:email,:name,:sex]"]; $sql->bindParam[':userid',$userid,PDO::PARAM_STR, 15]; $sql->bindParam[':password',$password,PDO::PARAM_STR, 32]; $sql->bindParam[':email',$email,PDO::PARAM_STR, 75]; $sql->bindParam[':name',$name,PDO::PARAM_STR]; $sql->bindParam[':sex',$sex,PDO::PARAM_STR]; if[$sql->execute[]]{ //echo " Inside ok loop "; $mem_id=$dbo->lastInsertId[]; /////////////////Posting confirmation mail //////
$em=""; // Change to your email address
$headers4=$em; $headers=""; $headers.="Reply-to: $headers4n"; $headers .= "From: $headers4n"; $headers .= "Errors-to: $headers4n"; //$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; $content="Your login details from ****** nn"; $content .="User ID= $userid n"; $content .="Password = $password_original n"; //echo $content; $sub="Your login details"; //mail[$email,"$sub",$content,$headers]; echo "Welcome, You have successfully signed up

Click here to
login

"; //////////////// End of posting mail ////////
}// if sql executed
else{print_r[$sql->errorInfo[]]; } }

Đăng nhập tập lệnh Php Đăng ký 1 Đăng nhập / Đăng nhập Tập lệnh Thay đổi mật khẩu
Change Password


plus2net.com

Sana

10-05-2012

Một số người có thể giải thích mục đích của varaible $ todo là gì? n y chúng ta đã sử dụng nó ở đây? cảm ơn trước

Shabhi

23-12-2014

Xin chào bất kỳ ai có thể viết mã ở đây rằng cách tạo bảng trong cơ sở dữ liệu MySQL. Xin vui lòng tôi cảm ơn nâng cao.
Please i Thanks advanced.

SMO

23-12-2014

Tải xuống tệp zip, bên trong bạn có thể thấy tên tệp dump_singup.txt. Tệp này có các lệnh SQL để tạo bảng.

Bài Viết Liên Quan

Chủ Đề