<!DOCTYPE HTML> <html> <head> <title>Add New Contacts</title> <link rel="stylesheet" href="addnew.css" type="text/css"/> </head> <body> <header> <nav class="navigation"> <a href="#">Edit Contacts</a> <a href="#">Delete Contact</a> <a href="#">Logout</a> </nav> </header> <div id="contact-form" class="mycontact"> <ul id="errors" class=""> <li id="info">Please recheck your form and Submit again: </li> </ul> <p id="success">Details Saved Successfully!!</p> <form action="validate_addnew.php" method="POST"> <label for="Fname">First Name <span class="required">*</span>:</label> <input type="text" id="First_Name" name="firstname" value="" pattern="[A-Za-z0-9]{50}" required="required" autofocus="autofocus"/> <label for="Mname">Middle Name :</label> <input type="text" id="Middle_Name" name="middlename" pattern="[A-Za-z]{30}" value=""/> <label for="Lname">Last Name <span class="required">*</span>:</label> <input type="text" id="Last_Name" name="lastname" value="" pattern="[A-Za-z]{40}" required="required"/> <label for="email">Email <span class="required">*</span>:</label> <input type="email" id="email" name="email" value="" placeholder="username@example.com" required="required"/> <label for="Phone1">Phone 1:<span class="required">*</span>:</label> <input type="text" id="contactHome" name="phone1" pattern="[0-9]{10}" value="" required="required"/> <label for="Phone2">Phone 2:</label> <input type="text" id="contactOffice" name="phone2" pattern="[0-9]{10}" value=""/> <label for="Address1">Address<span class="required">*</span>:</label> <textarea id="address1" name="address" required="required" data-maxlength="20"></textarea> <label for="city">City<span class="required">*</span>:</label> <input type="city" id="city" name="city" value="" required="required"/> <label for="state">State <span class="required">*</span>:</label> <input type="state" id="state" name="state" value="" required="required"/> <label for="country">Country <span class="required">*</span>:</label> <input type="country" id="country" name="country" value="" required="required"/> <label for="zip">Zip <span class="required">*</span>:</label> <input type="zip" id="zip" name="zip" value="" required="required"/> <input type="Submit" value="Submit" id="submit-button"/> <p id="required-desc"><span class="required">*</span> indicates a required field</p> </form> </div> </body> </html>
<?php session_start(); require('connection.php'); if(isset($_session['username'])) { header("Location:addnew.php"); } function cleaninput($strings) { $strings=trim($strings); if(get_magic_quotes_gpc()) { $strings=stripslashes($strings); } return mysql_real_escape_string($strings); } if(isset($_POST['submit'])) { $username=cleaninput($_POST('username')); $firstname=cleaninput($_POST('firstname')); $middlename=cleaninput($_POST('middlename')); $lastname=cleaninput($_POST('lastname')); $email=cleaninput($_POST('email')); $password=cleaninput($_POST('password')); $cnfpassword=cleaninput($_POST('cnfpassword')); if($username=="" || $firstname=="" || $lastname=="" || $email=="" || $password=="" || $cnfpassword=="") { echo "Please fill in all the required information!"; } else { if($password!=$cnfpassword) { echo "Passwords do not match! Please try again"; } else { $sqlquery =mysqli_query($connect, "SELECT * FROM usertable WHERE username='username'"); $return=mysqli_num_rows($sqlquery); if($return==1) { echo "Sorry!! This username is already taken! Please give another username"; } else { $adduser=mysqli_query($connect,"INSERT INTO usertable(username, firstname,middlename,lastname,email,password) VALUES('$username','$firstname','$middlename','$lastname','email','$password')"); echo "User Created successfully!<a href='login.php'>Click here </a>to login"; } } } } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)