Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("connection.php");
- if($_SERVER['REQUEST_METHOD'] == 'POST'){
- $fullName = test_input($_POST['fullname']);
- $Email = test_input($_POST['email']);
- $userName = test_input($_POST['username']);
- $passWord = test_input($_POST['password']);
- if(!empty($fullName) AND !empty($Email) AND !empty($userName) AND !empty($passWord)){
- if(filter_var($Email,FILTER_VALIDATE_EMAIL)){ // check if the email is valid or no
- if (preg_match('/^[0-9a-zA-Z ]+$/', $fullName)){ // the full name can contain only numbers ,letters and white space
- $request = 'INSERT INTO users(fullname,email,username,password)
- VALUES(:fullname,:email,:username,:password)';
- $stmt = $connect->prepare($request);
- $stmt->bindValue(':fullname',$fullName,PDO::PARAM_STR);
- $stmt->bindValue(':email',$Email,PDO::PARAM_STR);
- $stmt->bindValue(':username',$userName,PDO::PARAM_STR);
- $stmt->bindValue(':password',$passWord,PDO::PARAM_STR);
- $stmt->execute();
- echo 'new record add to database';
- }else{
- echo 'Unvalid Full Name ; Only Numbers ,Letters And White Space';
- exit();
- }
- }else{
- echo 'Unvalid Email';
- exit();
- }
- }else{
- echo 'Unvalid Input';
- exit();
- }
- }
- function test_input($inputField){
- $inputField = htmlspecialchars(strip_tags(stripcslashes($inputField)));
- return $inputField;
- }
- $connect = NULL;
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>codeJs</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Code Js : Register Now</h2>
- <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
- <div class="form-group">
- <label for="fullname">Full Name :</label>
- <input type="text" class="form-control" placeholder="Your Full Name" name="fullname">
- </div>
- <div class="form-group">
- <label for="email">Email :</label>
- <input type="text" class="form-control" placeholder="Your Email" name="email">
- </div>
- <div class="form-group">
- <label for="username">Username :</label>
- <input type="text" class="form-control" placeholder="Your Username" name="username">
- </div>
- <div class="form-group">
- <label for="password">Password:</label>
- <input type="text" class="form-control" placeholder="Your Password" name="password">
- </div>
- <button type="submit" class="btn btn-primary">Register</button>
- <a href='login.php' class="btn btn-warning">Log In</a>
- </form>
- </div>
- <style>form, h2{ width: 400px; margin: 0 auto; }
- h2{ margin-top: 50px; margin-bottom: 30px; color: #ea4444; }
- </style>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement