Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * These are the database login details
- */
- $username = "a2083177_mydb";
- $password = "password1";
- $db="a2083177_mydb";
- // Create connection
- $mysqli = new mysqli('mysql17.000webhost.com', $username, $password, $db);
- ?>
- <html>
- <body>
- <head>
- <title>Welcome to E-Box</title>
- <link rel="stylesheet" type="text/css" href="css/mystyle.css">
- <style>
- .error {color: #FF0000;}
- body
- {
- background-image: url("images/titlelogo.jpg");
- background-repeat:no-repeat;
- }
- </style>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- $firstnameErr = $surnameErr = $usernameErr = $emailErr = $passwordErr ="";
- $firstname = $surname = $username = $email = $password = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["firstname"])) {
- $firstnameErr = "firstname is required";
- } else {
- $firstname = test_input($_POST["firstname"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$firstname))
- {
- $firstnameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["surname"])) {
- $surnameErr = "Surname is required";
- } else {
- $surname = test_input($_POST["surname"]);
- }
- if (empty($_POST["username"])) {
- $usernameErr = "Username is required";
- } else {
- $username = test_input($_POST["username"]);
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- if (!filter_var($email, FILTER_VALIDATE_EMAIL))
- {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["password"])) {
- $passwordErr = "Password is required";
- } else {
- $password = test_input($_POST["password"]);
- }
- }
- $sql = "INSERT INTO userdata (firstname, surname, username, email, password)
- VALUES ('$firstname', '$surname', '$username', '$email', '$password')";
- if ($mysqli->query($sql) === TRUE) {
- echo "";
- } else {
- echo "Error: " . $sql . "<br>" . $mysqli->error;
- }
- $mysqli->close();
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <div class="newuser">
- <p style="margin-left:-350px; margin-top:50px; font-family:arial; font-size:20px;">Register</P>
- </div>
- <p><span class="error" style="margin-left:450px;">* required field.<a href="index.php" style="margin-left:205px;"> Log in </a></span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <div class="register">
- <input class="textbox" type="text" name="firstname" placeholder=" First name" value="<?php echo $firstname;?>">
- <span class="error">* <?php echo $firstnameErr;?></span></br></br>
- <input class="textbox" type="text" name="surname" placeholder="Surname" value="<?php echo $surname;?>">
- <span class="error">* <?php echo $surnameErr;?></span></br></br>
- <input class="textbox" type="text" name="username" placeholder="Username" value="<?php echo $username;?>">
- <span class="error">* <?php echo $usernameErr;?></span></br></br>
- <input class="textbox" type="text" name="email" placeholder="E-mail" value="<?php echo $email;?>">
- <span class="error">* <?php echo $emailErr;?></span></br></br>
- <input class="textbox" type="password" name="password" placeholder="Password" value="<?php echo $password;?>">
- <span class="error">* <?php echo $passwordErr;?></span></br></br>
- <input class="bluebutton" style="margin-left:270;" type="submit" value="Register" name="register" onclick="myFunction()">
- </div>
- </form>
- <script>
- function myFunction() {
- alert("You are successfully registered!");
- }
- </script>
- <!--
- <div id="userinfo">
- <?php
- echo "<br><br><br><br><br><h2><strong>You are successfully registered.</strong></h2>";
- echo "<h3>Your information:</h3>";
- echo "First name : ";
- echo $firstname;
- echo "<br>";
- echo "Surname : ";
- echo $Surname;
- echo "<br>";
- echo "User name : ";
- echo $username;
- echo "<br>";
- echo "E-mail : ";
- echo $email;
- echo "<br>";
- echo "Password : ";
- echo $password;
- ?>
- </div>
- -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement