Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost:9000";
- $username = "root";
- $password = "31Godavari!";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . $conn->error);
- }
- // Create database
- $sql = "CREATE DATABASE DB";
- if (!$conn->query($sql)) {
- echo "Error creating database: " . $conn->error;
- }
- else {
- echo "Database created successfully";
- }
- $dbname = "DB";
- // sql to create table
- $table = "CREATE TABLE $dbname.Details (
- username VARCHAR(20) PRIMARY KEY,
- password VARCHAR(20) NOT NULL,
- fullname VARCHAR(30) NOT NULL,
- email VARCHAR(20) NOT NULL)";
- if (!$conn->query($table)) {
- echo "Error creating table: " . $conn->error;
- } else {
- echo "Table Details created successfully";
- }
- $ins = "INSERT INTO Details (username, password, fullname, email)
- VALUES ($user, sha1($pwd), $fullname, $email)";
- if ($conn->query($ins) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $ins . "<br>" . $conn->error;
- }
- $conn->close();
- ?>
- <html lang="en-IN">
- <head>
- <title>Task3</title>
- <style>
- .error {color: #FF0000;}
- </style>
- </head>
- <body>
- <?php
- $userErr = $emailErr = $pwdErr = $fullnameErr = "";
- $user = $email = $pwd = $fullname = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["username"])) {
- $userErr = "UserName is required";
- } else {
- $user = test_input($_POST["username"]);
- if (strlen($user) < 5){
- $userErr = "Username should be between 5 to 10 characters";
- }
- elseif(strlen($input) > 10){
- $userErr = "Username should be between 5 to 10 characters";
- }
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["password"])) {
- $pwd = "";
- } else {
- $pwd = test_input($_POST["password"]);
- if(!preg_match("^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{5,}$")){
- $pwdErr="Password should be at least 5 characters long with one letter, digit and special character";
- }
- }
- if (empty($_POST["name"])) {
- $fullnameErr = "Full Name is required";
- } else {
- $fullname = test_input($_POST["name"]);
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h1>Test Form</h1>
- <p><span class="error">* required </span></p>
- <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Username: <input type="text" name="username" value="<?php echo $user;?>"/>
- <span class="error">* <?php echo $userErr;?></span><br><br>
- Password: <input type="text" name="password"value="<?php echo $pwd;?>" />
- <span class="error">* <?php echo $pwdErr;?></span><br><br>
- Full Name: <input type="text" name="name"value="<?php echo $fullname;?>" />
- <span class="error">* <?php echo $fullnameErr;?></span><br><br>
- E-mail address: <input type="text" name="email" value="<?php echo $email;?>"/>
- <span class="error">* <?php echo $emailErr;?></span><br><br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement