config.php page
<?php
$conn=mysql_connect("localhost","root","");
mysql_select_db("sampleproject",$conn) or die('Could not connect: ' . mysql_error());
?>
<html>
<head>
<script type="text/javascript">
function validate(form_id,username,password,retypepwd,email,phno) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var reg1 = /^[a-zA-Z0-9]{3,}$/;
var reg2 = /^[a-zA-Z0-9]{6,}$/;
var reg3 = /^[0-9]{10,}$/;
var username = document.forms[form_id].elements[username].value;
var password = document.forms[form_id].elements[password].value;
var retypepwd = document.forms[form_id].elements[retypepwd].value;
var email = document.forms[form_id].elements[email].value;
var phno = document.forms[form_id].elements[phno].value;
if(reg1.test(username) == false) {
alert('Invalid Username');
return false;
document.form.username.focus();
}
if(reg2.test(password) == false) {
alert('Invalid Password');
return false;
document.form.password.focus();
}
if(reg2.test(retypepwd) == false) {
alert('Passwords Not Matched');
return false;
}
if(!(password==retypepwd))
{
alert('passwords are not matched');
return false;
document.form.retypepwd.focus();
}
if(reg.test(email) == false) {
alert('Invalid Email Address');
return false;
document.form.email.focus();
}
if(reg3.test(phno) == false) {
alert('Invalid Phone Number');
return false;
document.form.phno.focus();
}
}
function fun1(){
a=document.getElementById('username').value;
// alert(a);
window.loacation="chkavailability.php?b="+a;
}
</script>
</head>
<body>
<form id="form_id" name="register" method="POST" action="register.php" onsubmit="javascript:return validate('form_id','username','password','retypepwd','email','phno');">
<table border="0">
<tr>
<td>* Username :</td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>* Password :</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td>* Re-Type Password :</td>
<td><input type="password" name="Retypepwd" id="retypepwd"></td>
</tr>
<tr>
<td>First Name :</td>
<td><input type="text" name="firstname" id="firstname"></td>
</tr>
<tr>
<td>Last Name :</td>
<td><input type="text" name="lastname" id="lastname"></td>
</tr
<tr>
<td>Gender :</td>
<td><input type="radio" name="sex" value="Female" id="sex">Female
<input type="radio" name="sex" value="Female" id="sex">Male
</td>
</tr>
<tr>
<td>* E-MAIL :</td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td>* Phone Number :</td>
<td><input type="text" name="phno" id="phno"></td>
</tr>
<tr>
<td></td>
<td><input type="reset" name="reset" value="Reset"> <input type="submit" name="submit" value="Submit" onClick="javascript:validateForm();"></td>
</tr>
</table>
<h2>* Fields are compulsary</h2>
</form>
<?php
if(isset($_POST['submit']))
{
include "config.php";
$username=$_POST['username'];
$password=$_POST['password'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$gender=$_POST['sex'];
$email=$_POST['email'];
$phno=$_POST['phno'];
$query="INSERT INTO simple(id,username,password,firstname,lastname,gender,email,phno) VALUES('','".$username."','".$password."','".$firstname."','".$lastname."','".$gender."','".$email."','".$phno."')";
// echo $query;
// alter table simple add unique (username);
mysql_query($query);
mkdir($username);
header("location:login.php");
}
else
{
echo "Records are Not Inserted";
}
?>
</body>
</html>
Post a Comment