Hi , everyone, i am new in web design and i have a liitle problem with my registration form.I have one php file which have the html code and the php and anothe with jquery. PHP code is for checking and enter the data in mysql table. The jquery code is also for validation. i have only on error and it's that when i enter data in fields the did't enter the table. can you help me where am i wrong ?
here is the signup.php :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/styletext.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="../js/form1.js"></script>
<title></title>
</style>
</head>
<body>
<div style="width:750px; height:500px;">
<br /><br />
<div><img src="../images/reg2.jpg" style="float:left; margin-right:12px;"></div>
<div><img src="../images/reg1.jpg" style="float:right;"></div>
<div id="regform" class="regform">
<span class="h1" style="padding-left: 130px; color:#002EB8;">РЕГИСТРАЦИЯ</span><br />
<form name="signupf" method="post" action="">
<table cellpadding="0" cellspacing="0" border="1" id="form">
<tr>
<td width="125px";>Имe*:</td>
<td><input type="text" name="first_name" id="fname" class="txtfld" style="font-size: 13px; float:left; color: #FF0000;"><span id="errorfname" class="formError"></span></td>
</tr>
<tr>
<td>Фамилия*:</td>
<td><input type="text" name="last_name" id="lname" class="txtfld" style="font-size: 13px; color: #FF0000;"><span id="errorlname" class="formError"></span></td>
</tr>
<tr>
<td>E-mail*:</td>
<td><input type="text" name="email" id="email" class="txtfld" style="font-size: 13px; color: #FF0000;"><span id="erroremail" class="formError"></span></td>
</tr>
<tr>
<td>Парола*:</td>
<td><input type="password" name="password" id="password" class="txtfld" style="font-size: 13px; color: #FF0000;"><span id="errorpass" class="formError"></span><p><span style='font-size: 11px; float:left;'>минимум 4 символа</span></p></td>
</tr>
<tr>
<td>Парола(повтори)*:</td>
<td><input type="password" name="password2" id="password2" class="txtfld" style="font-size: 13px; color: #FF0000;"><span id="errorpass2" class="formError"></span</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="signup" value="Регистрирай" class="button" id="submit"/><td>
</tr>
<tr><td></td>
<td><span id="formProgress" class="formProgress"></span></td>
</tr>
</table>
</form>
</div>
<br />
</div>
<?php
include"actionpages/dbconnect.php";
$errors='';
if(isset($_POST['submit'])){
if(!preg_match('/^[a-zA-Zа-яА-Я]/', stripslashes(trim($_POST['first_name']))))
{$errors = '<font color="red">Въведете валидно име.</font>';}
else{
$fname = mysql_real_escape_string($_POST['first_name']);
if(!preg_match('/^[a-zA-Zа-яА-Я]/',stripslashes(trim($_POST['last_name']))))
{$errors = '<font color="red">Въведете валидна фамилия.</font>';}
else{
$lname = mysql_real_escape_string($_POST['last_name']);
if (!preg_match('/^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)/', stripslashes(trim($_POST['email'])) ))
{$errors = '<font color="red">Въведете валиден e-mail адрес.</font>';}
else {
$email = mysql_real_escape_string($_POST['email']);
$sql="SELECT mail FROM account_data WHERE mail='$email'";
$result=mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result);
if($num>0) { $errors = '<font color="red">E-mail адресът, които сте избрали се използва.</font>';}
else { $mail=mysql_real_escape_string($_POST['email']);}
if(empty($_POST['email']))
{$errors = '<font color="red">Въведете e-mail адрес.</font>';}
else
{
$password=$_POST['password'];
if (empty($password))
{$errors = '<font color="red">Въведете парола.</font>';}
else{
if(!preg_match('/^[a-zA-Z0-9]/',stripslashes(trim($password))))
{$errors = '<font color="red">Въведели сте символ различен от букви и цифри.</font>';}
else{
if ($password != $_POST['password2'])
{$errors = '<font color="red">Двете пароли не са идентични.</font>'; }
else{
if((strlen($password)<4) || (strlen($password)>20))
{$errors = '<font color="red">Паролата трябва да е между 4 и 16символа.</font>';}
}
$password=md5($password);
}
}
}
}
}
}
if(!empty($errors))
{ die('reg not ok');
}
else
{
$sql="INSERT INTO account_data(FirstName,LastName,mail,pass,city)VALUES('$fname','$lname','$email','$password','0')";
$result=mysql_query($sql,$con) or die(mysql_error());
die( "reg ok");
}
}
?>
</body>
</html>
and here is form1.js
// JavaScript Document
$(document).ready(function() {
$('#regform #submit').click(function() {
// Fade in the progress bar
$('#regform #formProgress').hide();
$('#reform #formProgress').html();
$('#regform #formProgress').fadeIn();
// Disable the submit button
$('#regform #submit').attr("disabled", "disabled");
// Clear and hide any error messages
$('#regform .formError').html('');
// Set temaprary variables for the script
var isFocus=0;
var isError=0;
// Get the data from the form
var fname=$('#regform #fname').val();
var lname=$('#regform #lname').val();
var email=$('#regform #email').val();
var pass=$('#regform #password').val();
var pass2=$('#regform #password2').val();
// Validate the data
if(fname=='') {
$('#regform #errorfname').html('Въведете име.');
if(isFocus==0) {
$('#regform #fname').focus();
isFocus=1;
}
isError=1;
} else {
var reg = /^([a-zA-Zа-яА-Я]{1,20})$/;
if(reg.test(fname)==false) {
$('#regform #errorfname').html('Въведете валидно име.');
if(isFocus==0) {
$('#regform #fname').focus();
isFocus=1;
}
isError=1;
}
}
if(lname=='') {
$('#regform #errorlname').html('Въведете фамилия.');
if(isFocus==0) {
$('#regform #lname').focus();
isFocus=1;
}
isError=1;
} else {
var reg = /^([A-Za-zа-яА-Я]{1,20})$/;
if(reg.test(lname)==false) {
$('#regform #errorlname').html('Въведете валидна фамилия.');
if(isFocus==0) {
$('#regform #lname').focus();
isFocus=1;
}
isError=1;
}
}
if(email=='') {
$('#regform #erroremail').html('Въведете e-mail адрес.');
if(isFocus==0) {
$('#regform #email').focus();
isFocus=1;
}
isError=1;
} else {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(reg.test(email)==false) {
$('#regform #erroremail').html('Въведете валиден e-mail адрес.');
if(isFocus==0) {
$('#regform #email').focus();
isFocus=1;
}
isError=1;
}
}
if(pass=='') {
$('#regform #errorpass').html('Въведете парола.');
if(isFocus==0) {
$('#regform #password').focus();
isFocus=1;
}
isError=1;
} else {
var reg = /^([A-Za-z0-9]{4,16})$/;
if(reg.test(pass)==false) {
$('#regform #errorpass').html('Въведете парола между 4 и 16 символа.');
if(isFocus==0) {
$('#regform #password').focus();
isFocus=1;
}
isError=1;
}
}
if(pass2=='') {
$('#regform #errorpass2').html('Потвърдете паролата.');
if(isFocus==0) {
$('#regform #password2').focus();
isFocus=1;
}
isError=1;
} else {
var reg = /^([A-Za-z0-9]{4,16})$/;
if((reg.test(pass2))!=(reg.test(pass))) {
$('#regform #errorpass2').html('Паролите не са идентични.');
if(isFocus==0) {
$('#regform #password2').focus();
isFocus=1;
}
isError=1;
}
}
// Terminate the script if an error is found
if(isError==1) {
$('#regform #formProgress').html('');
$('#regform #formProgress').hide();
// Activate the submit button
$('#regform #submit').attr("disabled", "");
return false;
}
$.ajaxSetup ({
cache: false
});
var dataString = 'first_name='+ fname + 'last_name='+lname+ '&email=' + email + '&password=' + pass;
$.ajax({
type: "POST",
url:"../pages/signup.php",
data: dataString,
success: function(msg) {
//alert(msg);
// Check to see if the mail was successfully sent
if(msg=='reg ok') {
// Update the progress bar
$('#regform #formProgress').html('REg ok');
} else {
$('#regform #formProgress').html
('There was an error . Please try again.');
}
// Activate the submit button
$('#regform #submit').attr("disabled", "");
},
error: function(ob,errStr) {
$('#regform #formProgress').html('');
alert('There was an error 2. Please try again.');
// Activate the submit button
$('#regform #submit').attr("disabled", "");
}
});
return false;
});
});
// Check to see if the mail was successfully sent
if(msg=='reg ok') {
// Update the progress bar
$('#regform #formProgress').html('REg ok');
} else {
$('#regform #formProgress').html
('There was an error . Please try again.');- after submit i recieve this error!!!