I have followed some tutorials to create a registration form with some javascript.
I have table to register new members to the website. then a parse_register to handle the php and then custom_js for the javscript.
Well what is happening at the moment is that having filled in the registration form, and then pressing the button to register nothing happens.
I have looked over and over at the code but can't spot the mistake(s).
The connect file is working as it is echoing out connected successfully, so no problem with connecting to the database it seems.
My header looks like this, connecting to the database.
<?php
require_once("scripts/connect.php");
session_start();
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];
?>
<html>
<head>
<title><?php echo $page_title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="keywords" content="<?php echo $page_keywords; ?>" />
<meta name="description" content="<?php echo $page_description; ?>" />
<link rel="stylesheet" type="text/css" href="css/green.css" />
<link rel="stylesheet" type="text/css" href="css/custom.css" />
<script type="text/javascript" src="js/jquery_1.6.2.js"></script>
<script type="text/javascript" src="js/custom_js.js"></script>
<?php require("scripts/functions.php"); ?>
</head>
<body>
<div id="wrapper">
The register.php is next As you can see i have commented
out verify password for now, id like to add that however.
<?php
// page properties that are used by header.php to use within this page
$page_title = 'whoknowsyet';
$page_keywords = ', registation';
$page_description = 'reg, Sign up/register ';
?>
<?php include 'header.php'; ?>
<div style="float:left;" align="center">
<table id="registration">
<tr>
<td>First Name: </td>
<td><input type="text" size="30" name="firstname" id="firstname"></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" size="30" name="lastname" id="lastname"></td>
</tr>
<tr>
<td>Email Address: </td>
<td><input type="text" size="30" name="email" id="email"></td>
</tr>
<tr>
<td>Verify Email: </td>
<td><input type="text" size="30" name="verifyemail" id="verifyemail"></td>
</tr>
<tr>
<td>Username: </td>
<td><input type="text" size="30" maxlength="15" name="username" id="username"></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" size="30" name="password" id="password"></td>
</tr>
<!--<tr>
<td> Verify Password: </td>
<td><input type="password" size="30" name="repassword" id="repassword"></td>
</tr>--->
<tr><td colspan="2" align="right"><span id="reg_span" style="padding-right: 10px;"></span><button name="reg_submit" id="reg_submit">Register
</button></td></tr>
</table>
</div>
<div align="center" class="hidden" id="reg_success">
Success
</div>
<div align="center" class="hidden" id="reg_failed">
Sorry
</div>
<div style="clear:both;"></div>
<?php include 'footer.php'; ?>
Next is my parse_register.php code, just to repeat what i said at the top of this post
i removed the email activation side of things for now as i am using localhost.
<?php
include_once("connect.php");
if (isset($_POST['action'])&& $_POST['action']== "check"){
$email = mysql_real_escape_string(strip_tags($_POST['email']));
$username = mysql_real_escape_string(strip_tags($_POST['username']));
if(strpos($email,"@")!==false){
$check_email = explode("@", $email);
if(strpos($check_email[1], ".")===false){
echo 3;
exit();
}
}else{
echo 3;
exit();
}
$email_query = mysql_query("SELECT id FROM users WHERE email='$email' LIMIT 1");
if(mysql_num_rows($email_query)== 1){
echo 1;
exit();
}else{
$username_query = mysql_query("SELECT username FROM users WHERE username='$username' LIMIT 1");
if(mysql_num_rows($username_query)== 1){
echo 2;
exit();
}else{
echo 0;
exit();
}
}
}
if( isset($_POST['action']) && $_POST['action']=="register"){
$firstname = mysql_real_escape_string(strip_tags($_POST['firstname']));
$lastname = mysql_real_escape_string(strip_tags($_POST['lastname']));
$email = mysql_real_escape_string(strip_tags($_POST['email']));
$username = mysql_real_escape_string(strip_tags($_POST['username']));
$password = mysql_real_escape_string(strip_tags($_POST['password']));
//$repassword = mysql_real_escape_string(strip_tags($_POST['repassword']));
//$pass = md5(md5($password));
$date_activated = date("F d, Y"); //March 07, 2011
$reg_query = mysql_query("INSERT INTO users VALUES (firstname, lastname, email, username, password) VALUES
('''ucfirst(strolower($firstname)).''', '''ucfirst(strolower($lastname)).''', '$email', '$username', '''.md5($password).''', '$date_activated')");
if($reg_query){
$new_userid = mysql_insert_id();
mkdir("users/$new_userid",0755);
mkdir("users/$new_userid/images",0755);
mkdir("users/$new_userid/media",0755);
}
echo 1;
exit();
} else {
echo 0;
exit();
}
}
?>
finally the custom_js script:
$(document).ready(function(){
$("#reg_submit").click(function(){
var process = true;
$("#registration input").each(function(){
if($.trim()this.value)== ""){
process = false;
}
});
if(process == true){
var firstname = $.trim($("#firstname").val());
var lastname = $.trim($("#lastname").val());
var username = $.trim($("#username").val());
var password= $.trim($("#password").val());
var email = $.trim($("#email").val());
var verifyemail = $.trim($("#verifyemail").val());
if(username.length >=4){
if(email==verifyemail){
//$(#reg_span).html("img src='image/loading.gif' height='20' align='absmiddle'/>");
$(#reg_span).html("loading");
$.post("scripts/parse_register.php",{action: "check", email:email, usename:username }, function(check_data){
if(check_data == 0){
$(#registration input, #registration button").each(function(){
$("#"+this.id).attr("disabled", "disabled");
});
$.post("scripts/parse_register.php",{action: "register", firstname:firstname, lastname:lastname, email:email,
username:username, password:password }, function(reg_data){
if(reg_data == 1){
$("#reg_span").empty();
$("#reg_success").fadeIn(500);
}else if(reg_data ==0){
$("#reg_span").empty();
$("#reg_failed").fadeIn(500);
}
});
}else if (check_data == 1){
$("#reg_span").html("<font color='#ff0000' size='-1'>Email has already been used.</font>");
}else if (check_data == 2){
$("#reg_span").html("<font color='#ff0000' size='-1'>Username taken</font>");
}else if (check_data == 3){
$("#reg_span").html("<font color='#ff0000' size='-1'>Email invalid</font>");
}else{
alert(check_data);
}
});
else{
$("#reg_span").html("<font color='#ff0000' size='-1'>Email fields do not match</font>");
}
}else{
$("#reg_span").html("<font color='#ff0000' size='-1'>Username is to short.</font>");
}
}else{
$("#reg_span").html("<font color='#ff0000' size='-1'>All fields required</font>");
}
});
});
Sorry for chucking all the code on here at once. Just thought it may save time in the long run.
If anyone can help solve the problem it will be most appreciated.
Thanks