Current location: Hot Scripts Forums » Programming Languages » PHP » Help With Registration page!


Help With Registration page!

Reply
  #1 (permalink)  
Old 11-03-10, 12:07 AM
phphelpme phphelpme is offline
Newbie Coder
 
Join Date: Jul 2010
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Help With Registration page!

hi i need help with a registration script that tells you instantly if the email is used , and if they didnt fill in a required thing. so here is the script that i have so far that tells you if the username is taken , i want to switch it to email , so how do i do that? i don't want them to have a username , i just want them to have first name , last name , age , zip , phone , email , password , and city. here is my script , I've tried all i can to change it to the desired thing i need but i cant , here is my codes! PLEASE HELP!

HERE IS signup.php
PHP Code:

<?php // signup.php




include_once 'header.php';

echo <<<_END
<script>
function checkUser(user)
{
  if (user.value == '')
  {
    document.getElementById('info').innerHTML = ''
    return
  }

  params  = "user=" + user.value
  request = new ajaxRequest()
  request.open("POST", "checkuser.php", true)
  request.setRequestHeader("Content-type",
    "application/x-www-form-urlencoded")
  request.setRequestHeader("Content-length", params.length)
  request.setRequestHeader("Connection", "close")
  
  request.onreadystatechange = function()
  {
    if (this.readyState == 4)
    {
      if (this.status == 200)
      {
        if (this.responseText != null)
        {
          document.getElementById('info').innerHTML =
            this.responseText
        }
        else alert("Ajax error: No data received")
      }
      else alert( "Ajax error: " + this.statusText)
    }
  }
  request.send(params)
}

function ajaxRequest()
{
  try
  {
    var request = new XMLHttpRequest()
  }
  catch(e1)
  {
    try
    {
      request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e2)
    {
      try
      {
        request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch(e3)
      {
        request = false
      }
    }
  }
  return request
}
</script>


<script>
function checkEmail(email)
{
  if (user.value == '')
  {
    document.getElementById('info').innerHTML = ''
    return
  }

  params  = "Email=" + email.value
  request = new ajaxRequest()
  request.open("POST", "checkemail.php", true)
  request.setRequestHeader("Content-type",
    "application/x-www-form-urlencoded")
  request.setRequestHeader("Content-length", params.length)
  request.setRequestHeader("Connection", "close")
  
  request.onreadystatechange = function()
  {
    if (this.readyState == 4)
    {
      if (this.status == 200)
      {
        if (this.responseText != null)
        {
          document.getElementById('info').innerHTML =
            this.responseText
        }
        else alert("Ajax error: No data received")
      }
      else alert( "Ajax error: " + this.statusText)
    }
  }
  request.send(params)
}

function ajaxRequest()
{
  try
  {
    var request = new XMLHttpRequest()
  }
  catch(e1)
  {
    try
    {
      request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e2)
    {
      try
      {
        request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch(e3)
      {
        request = false
      }
    }
  }
  return request
}
</script>
<h3>Sign up Form</h3>
_END;

$error $user $pass $Email "";
if (isset(
$_SESSION['user'])) destroySession();

if (isset(
$_POST['user']))
{
  
$user sanitizeString($_POST['user']);
  
$pass sanitizeString($_POST['pass']);
  
$Email sanitizeString($_POST['email']);
  
  if (
$user == "" || $pass == "" || $Email == "")
  {
    
$error "Not all fields were entered<br /><br />";
  }
  else
  {
    
$query "SELECT * FROM members WHERE user='$user'";

    if (
mysql_num_rows(queryMysql($query)))
    {
      
$error "That username already exists<br /><br />";
    }
    
    
$query "SELECT * FROM members WHERE user='$Email'";
    
    if (
mysql_num_rows(queryMysql($query)))
    {
      
$error "That Email already exists in our database!";
    }
    else
    {
      
$query "INSERT INTO members VALUES('$user','$pass','$Email')";
      
queryMysql($query);
      die(
"<h4>Before you can login , check your email for a confermation email!");
    }
    
  }
}

echo <<<_END

<form method='post' action='signup.php'>
$error
Username <input type='text' maxlength='16' name='user' value='
$user'
  onBlur='checkUser(this)'/><span id='info'></span><br />
Password <input type='Password' maxlength='16' name='pass'
  value='
$pass' /><br />
  Email: <input type='text' maxlength='35' name='email' value='
$Email'
  onBlur='checkEmail(this)'/><span id='info'></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<input type='submit' value='Signup' />
</form>
_END;
?>
HERE IS header.php
PHP Code:

<?php // header.php
include 'functions.php';

session_start();

if (isset(
$_SESSION['user']))

{

$user $_SESSION['user'];

$loggedin TRUE;

}

else 
$loggedin FALSE;

echo 
"<html><head><title>$appname";

if (
$loggedin) echo " ($user)";

echo 
"<center></title></head><body><font face='verdana' size='2'>";

echo 
"<center><h2>$appname</h2>";

if (
$loggedin)

{

echo 
"<b>$user</b>:

<a href='members.php?view=
$user'>Home</a> |
<a href='members.php'>Members</a> |
<a href='friends.php'>Friends</a> |
<a href='messages.php'>Messages</a> |
<a href='profile.php'>Profile</a> |
<a href='logout.php'>Log out</a>"
;
}

else

{

echo 
"<a href='index.php'>Home</a> |
<a href='signup.php'>Sign up</a> |
<a href='login.php'>Log in</a>"
;

}

?>
AND HERE IS functions.php
PHP Code:

<?php // functions.php
$dbhost  'localhost';    
$dbname  'phplesson';
$dbuser  'glenn';     
$dbpass  '********';     
$appname "Social Network"

 

mysql_connect($dbhost$dbuser$dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

 

function 
createTable($name$query)

{

if (
tableExists($name))

{

echo 
"Table '$name' already exists<br />";

}

else

{

queryMysql("CREATE TABLE $name($query)");

echo 
"Table '$name' created<br />";

}

}

 

function 
tableExists($name)

{

$result queryMysql("SHOW TABLES LIKE '$name'");

return 
mysql_num_rows($result);

}

 

function 
queryMysql($query)

{

$result mysql_query($query) or die(mysql_error());

return 
$result;

}

 

function 
destroySession()

{

$_SESSION=array();

 

if (
session_id() != "" || isset($_COOKIE[session_name()]))

setcookie(session_name(), ''time()-2592000'/');

 

session_destroy();

}

 

function 
sanitizeString($var)

{

$var strip_tags($var);

$var htmlentities($var);

$var stripslashes($var);

return 
mysql_real_escape_string($var);

}

 

function 
showProfile($user)

{

if (
file_exists("$user.jpg"))

echo 
"<img src='$user.jpg' border='1' align='left' />";

$result queryMysql("SELECT * FROM profiles WHERE user='$user'");

if (
mysql_num_rows($result))
{
$row mysql_fetch_row($result);
echo 
stripslashes($row[1]) . "<br clear=center /><br />";
}
}
?>
HERE IS checkuser.php
PHP Code:

<?php // checkuser.php
include_once 'functions.php';

if (isset(
$_POST['user']))

{

$user sanitizeString($_POST['user']);

$query "SELECT * FROM members WHERE user='$user'";

if (
mysql_num_rows(queryMysql($query)))

echo 
"<font color=red>&nbsp;&larr;

Sorry, already taken</font>"
;

else echo 
"<font color=green>&nbsp;&larr;

Username avalible!</font>"
;

}
?>
IS THAT WHERE I NEED TO EDIT WHAT SHOWS UP?

Last edited by phphelpme; 11-03-10 at 12:17 AM.
Reply With Quote
  #2 (permalink)  
Old 11-03-10, 09:53 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Well the first problem is, your database table doesn't seem to be setup to accept all the fields you want to include.
From what I can deduce, your table has only three columns (one for each - user name, password and email).

In your main page you have these two queries:
PHP Code:

$query "SELECT * FROM members WHERE user='$user'";
$query "SELECT * FROM members WHERE user='$Email'"
The first query is correct because it's checking the user name against the values in the user column.
The second query is incorrect because the email address is not stored in the user column.
So it should be checking the email address against the values in the email column.

And to make your checkEmail(email) function work, you just need to make a copy of checkuser.php and rename it to checkemail.php
And then change it to something like this:

checkemail.php
PHP Code:

 <?php // checkuser.php
include_once 'functions.php';

if (isset(
$_POST['email']))

{

$email sanitizeString($_POST['email']);

$query "SELECT * FROM members WHERE email='$email'"// Change email to whatever the email column name is.

if (mysql_num_rows(queryMysql($query)))

echo 
"<font color=red>&nbsp;&larr;

Sorry, already taken</font>"
;

else echo 
"<font color=green>&nbsp;&larr;

  email avalible!</font>"
;

}
?>
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 11-03-10, 11:30 PM
phphelpme phphelpme is offline
Newbie Coder
 
Join Date: Jul 2010
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
It didnt work

i hate doing this , i waste my whole day on this crap
Reply With Quote
  #4 (permalink)  
Old 11-04-10, 12:51 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You have to make sure your column names are correct in the queries.
Sense I don't know the exact names you use, I can only put in names that would make sense to me.
So edit your queries as needed to match what's in your members table.

And don't worry so much, take a break and try again.
I sucked when I was learning, but I kept at it and I finally learned.
Your not going to be perfect in just a couple of days or even a couple months.
I have been doing this for about 4 years.
Just keep trying, you'll get it.


Hint: Get your checkuser.php and checkemail.php programs working by themselves, so they produce the desired output.
That output is what will be returned to AJAX.
__________________
Jerry Broughton

Last edited by job0107; 11-04-10 at 01:00 AM.
Reply With Quote
  #5 (permalink)  
Old 11-04-10, 05:42 PM
phphelpme phphelpme is offline
Newbie Coder
 
Join Date: Jul 2010
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
ok , so how would i change my ajax? im confused
Reply With Quote
  #6 (permalink)  
Old 11-05-10, 01:17 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Obviously your just going too fast, because you are making a lot of little mistakes.
Your main file should look like this:
PHP Code:

<?php // signup.php

include_once 'header.php';

echo <<<_END
<script>
function checkUser(user)
{
  if (user.value == '')
  {
    document.getElementById('info1').innerHTML = ''
    return
  }

  params  = "user=" + user.value
  request = new ajaxRequest()
  request.open("POST", "checkuser.php", true)
  request.setRequestHeader("Content-type",
    "application/x-www-form-urlencoded")
  request.setRequestHeader("Content-length", params.length)
  request.setRequestHeader("Connection", "close")

  request.onreadystatechange = function()
  {
    if (this.readyState == 4)
    {
      if (this.status == 200)
      {
        if (this.responseText != null)
        {
          document.getElementById('info1').innerHTML =
            this.responseText
        }
        else alert("Ajax error: No data received")
      }
      else alert( "Ajax error: " + this.statusText)
    }
  }
  request.send(params)
}

function ajaxRequest()
{
  try
  {
    var request = new XMLHttpRequest()
  }
  catch(e1)
  {
    try
    {
      request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e2)
    {
      try
      {
        request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch(e3)
      {
        request = false
      }
    }
  }
  return request
}
</script>


<script>
function checkEmail(email)
{
  if (email.value == '')
  {
    document.getElementById('info2').innerHTML = ''
    return
  }

  params  = "Email=" + email.value
  request = new ajaxRequest()
  request.open("POST", "checkemail.php", true)
  request.setRequestHeader("Content-type",
    "application/x-www-form-urlencoded")
  request.setRequestHeader("Content-length", params.length)
  request.setRequestHeader("Connection", "close")

  request.onreadystatechange = function()
  {
    if (this.readyState == 4)
    {
      if (this.status == 200)
      {
        if (this.responseText != null)
        {
          document.getElementById('info2').innerHTML =
            this.responseText
        }
        else alert("Ajax error: No data received")
      }
      else alert( "Ajax error: " + this.statusText)
    }
  }
  request.send(params)
}

function ajaxRequest()
{
  try
  {
    var request = new XMLHttpRequest()
  }
  catch(e1)
  {
    try
    {
      request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e2)
    {
      try
      {
        request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch(e3)
      {
        request = false
      }
    }
  }
  return request
}
</script>
<h3>Sign up Form</h3>
_END;

$error $user $pass $Email "";
if (isset(
$_SESSION['user'])) destroySession();

if (isset(
$_POST['user']))
{
  
$user sanitizeString($_POST['user']);
  
$pass sanitizeString($_POST['pass']);
  
$Email sanitizeString($_POST['email']);

  if (
$user == "" || $pass == "" || $Email == "")
  {
    
$error "Not all fields were entered<br /><br />";
  }
  else
  {
    
$query "SELECT * FROM members WHERE user='$user'";

    if (
mysql_num_rows(queryMysql($query)))
    {
      
$error "That username already exists<br /><br />";
    }

    
$query "SELECT * FROM members WHERE user='$Email'";

    if (
mysql_num_rows(queryMysql($query)))
    {
      
$error "That Email already exists in our database!";
    }
    else
    {
      
$query "INSERT INTO members VALUES('$user','$pass','$Email')";
      
queryMysql($query);
      die(
"<h4>Before you can login , check your email for a confermation email!");
    }

  }
}

echo <<<_END

<form method='post' action='signup.php'>
$error
Username <input type='text' maxlength='16' name='user' value='
$user'
  onBlur='checkUser(this)'/><span id='info1'></span><br />
Password <input type='Password' maxlength='16' name='pass'
  value='
$pass' /><br />
  Email: <input type='text' maxlength='35' name='email' value='
$Email'
  onBlur='checkEmail(this)'/><span id='info2'></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<input type='submit' value='Signup' />
</form>
_END;
?>
And then I used a simple checkuser.php and checkemail.php files to test it.

checkuser.php
PHP Code:

<?php // checkuser.php
//include_once 'functions.php';

if (isset($_POST['user']))

{

echo 
$_POST['user'];

/*$query = "SELECT * FROM members WHERE user='$user'";

if (mysql_num_rows(queryMysql($query)))

echo "<font color=red>&nbsp;&larr;

Sorry, already taken</font>";

else echo "<font color=green>&nbsp;&larr;

Username avalible!</font>";
*/
}
?>
checkemail.php
PHP Code:

<?php // checkuser.php
//include_once 'functions.php';

if (isset($_POST['Email']))

{

echo 
$_POST['Email'];

/*$query = "SELECT * FROM members WHERE user='$user'";

if (mysql_num_rows(queryMysql($query)))

echo "<font color=red>&nbsp;&larr;

Sorry, already taken</font>";

else echo "<font color=green>&nbsp;&larr;

Username avalible!</font>";
*/
}
?>
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks

Tags
ajax, javascript, php code, php form, php register


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking to an Iframe page Fmgraphics HTML/XHTML/XML 0 04-24-09 07:55 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Passing a variable to another page tapir PHP 8 02-16-05 05:38 PM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 08:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.