PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,144 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,739 people online right now. Registration is fast and FREE... Join Now!




registration error

 

registration error

cred493

6 Nov, 2009 - 06:37 PM
Post #1

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

i made a registration page and i am trying to use it but when someone try to register this comes up

$connect=mysql_connect("mysql9.000webhost.com","a7606951_cred493", "m05171996"); mysql_select_db("a7606951_TPW",$connect) or die (mysql_errno().": ".mysql_error()."");


then


Fatal error: Call to undefined function valid_email() in /home/a7606951/public_html/register.php on line 7

here is my register code


CODE

<?php
require_once('db.php');


    if(isset($_POST['register']))
    {
        if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE)
        {
        
            $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());
            
            $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());
    
            if(mysql_num_rows($getUser)==1)
            {//there's only one MATRIX :PP
            
                $row = mysql_fetch_assoc($getUser);
                $headers =     'From: webmaster@ourdomainhere.com' . "\r\n" .
                            'Reply-To: webmaster@ourdomainhere.com' . "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
                $subject = "Activation email from ourdomainhere.com";
                $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&amp;key=".$row['Random_key']." Thank you for joining";
                if(mail($row['Email'], $subject, $message, $headers))
                {//we show the good guy only in one case and the bad one for the rest.
                    $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
                }
                else {
                    $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine';
                }
            }
            else {
                $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.';
            }
                            
        }
        else {        
            $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match';    
        }
    }
?>
<?php if(isset($error)){ echo $error;}?>
<?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br />
    Password: <input type="password" id="password" name="password" size="32" value="" /><br />
    Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br />
    Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br />
    <input type="submit" name="register" value="register" /><br />
</form>
<? } ?>



here is my database code
CODE

$connect=mysql_connect("mysql9.000webhost.com","a7606951_cred493",
    "m05171996");
mysql_select_db("a7606951_TPW",$connect) or
   die (mysql_errno().":<b> ".mysql_error()."</b>");


please help

This post has been edited by cred493: 6 Nov, 2009 - 06:38 PM

User is offlineProfile CardPM
+Quote Post


Dannyboy997

RE: Registration Error

6 Nov, 2009 - 06:51 PM
Post #2

D.I.C Head
**

Joined: 17 Apr, 2009
Posts: 77



Thanked: 2 times
My Contributions
there is no such function : valid_email();

for this you can create your own function:
CODE


function valid_email($email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
        // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
        return false;
    }
    // Split it into sections to make life easier
    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
         if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
            return false;
        }
    }    
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
        $domain_array = explode(".", $email_array[1]);
        if (sizeof($domain_array) < 2) {
                return false; // Not enough parts to domain
        }
        for ($i = 0; $i < sizeof($domain_array); $i++) {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
                return false;
            }
        }
    }
    return true;
}




hope this helps!!




User is online!Profile CardPM
+Quote Post

cred493

RE: Registration Error

6 Nov, 2009 - 07:06 PM
Post #3

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

so is this how i am supposed to do it

CODE

<?php
require_once('db.php');


    if(isset($_POST['register']))
    {
        if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!=''
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
        // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
        return false;
    }
    // Split it into sections to make life easier
    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
         if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
            return false;
        }
    }    
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
        $domain_array = explode(".", $email_array[1]);
        if (sizeof($domain_array) < 2) {
                return false; // Not enough parts to domain
        }
        for ($i = 0; $i < sizeof($domain_array); $i++) {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
                return false;
            }
        }
    }
    return true;
}
($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE)
        {
        
            $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());
            
            $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());
    
            if(mysql_num_rows($getUser)==1)
            {//there's only one MATRIX :PP
            
                $row = mysql_fetch_assoc($getUser);
                $headers =     'From: webmaster@ourdomainhere.com' . "\r\n" .
                            'Reply-To: webmaster@ourdomainhere.com' . "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
                $subject = "Activation email from ourdomainhere.com";
                $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&amp;key=".$row['Random_key']." Thank you for joining";
                if(mail($row['Email'], $subject, $message, $headers))
                {//we show the good guy only in one case and the bad one for the rest.
                    $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
                }
                else {
                    $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine';
                }
            }
            else {
                $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.';
            }
                            
        }
        else {        
            $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match';    
        }
    }
?>
<?php if(isset($error)){ echo $error;}?>
<?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br />
    Password: <input type="password" id="password" name="password" size="32" value="" /><br />
    Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br />
    Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br />
    <input type="submit" name="register" value="register" /><br />
</form>
<? } ?>

User is offlineProfile CardPM
+Quote Post

Dannyboy997

RE: Registration Error

6 Nov, 2009 - 07:14 PM
Post #4

D.I.C Head
**

Joined: 17 Apr, 2009
Posts: 77



Thanked: 2 times
My Contributions
to make it simpler just put it in a function then call the function:
CODE


function valid_email($email)
{

the valid_email code here...

}

if(valid_email($_POST['email'])==TRUE)
{

the rest of your code...

}



this way your code will be easier to read and much easier to debug and manage later on.

if you want you can put the function code in a seperate file and just include that file..

hope this helps
User is online!Profile CardPM
+Quote Post

cred493

RE: Registration Error

6 Nov, 2009 - 07:35 PM
Post #5

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

now it says

Parse error: syntax error, unexpected T_FUNCTION in /home/a7606951/public_html/register.php on line 8

CODE

<?php
require_once('db.php');
include('email_function.php');


    if(isset($_POST['register']))
    {
        if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' function valid_email($email)
==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE)
        {
      
            $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());
          
            $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());
  
            if(mysql_num_rows($getUser)==1)
            {//there's only one MATRIX :PP
          
                $row = mysql_fetch_assoc($getUser);
                $headers =     'From: webmaster@ourdomainhere.com' . "\r\n" .
                            'Reply-To: webmaster@ourdomainhere.com' . "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
                $subject = "Activation email from ourdomainhere.com";
                $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&amp;key=".$row['Random_key']." Thank you for joining";
                if(mail($row['Email'], $subject, $message, $headers))
                {//we show the good guy only in one case and the bad one for the rest.
                    $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
                }
                else {
                    $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine';
                }
            }
            else {
                $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.';
            }
                          
        }
        else {        
            $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match';    
        }
    }
?>
<?php if(isset($error)){ echo $error;}?>
<?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br />
    Password: <input type="password" id="password" name="password" size="32" value="" /><br />
    Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br />
    Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br />
    <input type="submit" name="register" value="register" /><br />
</form>
<? } ?>

User is offlineProfile CardPM
+Quote Post

Dannyboy997

RE: Registration Error

6 Nov, 2009 - 08:01 PM
Post #6

D.I.C Head
**

Joined: 17 Apr, 2009
Posts: 77



Thanked: 2 times
My Contributions
ok i see what you did wrong very easy to fix:
QUOTE

CODE

if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' function valid_email($email)



change it to this:
CODE

if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($email))


so you put the function before the valid_email and thats how you create a function not calling it and you didn't put a '&&' so thats another reason why your code was all messed up!!

you also forgot a ')' at the end.

hope this helps

This post has been edited by Dannyboy997: 6 Nov, 2009 - 08:01 PM
User is online!Profile CardPM
+Quote Post

cred493

RE: Registration Error

7 Nov, 2009 - 01:12 PM
Post #7

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

i changes my login page but now it says

Parse error: syntax error, unexpected T_STRING in /home/a9943699/public_html/login.php on line 19

here is my code
CODE

<?php

//Database Information

$dbhost = "mysql13.000webhost.com";
$dbname = "a9943699_TPI";
$dbuser = "a9943699_TPI";
$dbpass = "05171996m";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);

$query = “select * from users where username=’$username’ and password=’$password’;

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = “Bad Login”;
    include “login.html”;

} else {
    $_SESSION[‘username’] = “$username”;
    include “memberspage.php”;
}

?>




User is offlineProfile CardPM
+Quote Post

Dannyboy997

RE: Registration Error

7 Nov, 2009 - 01:22 PM
Post #8

D.I.C Head
**

Joined: 17 Apr, 2009
Posts: 77



Thanked: 2 times
My Contributions
well you are missing a ' " ' at the end of line 19

your code:
QUOTE

CODE

$query = “select * from users where username=’$username’ and password=’$password’;



what it should look like:
CODE

$query = “select * from users where username=’$username’ and password=’$password’";

so you just have to add the ' " ' just before the semi colon.

Hope this helps!
User is online!Profile CardPM
+Quote Post

cred493

RE: Registration Error

7 Nov, 2009 - 01:27 PM
Post #9

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

thanks biggrin.gif
User is offlineProfile CardPM
+Quote Post

cred493

RE: Registration Error

7 Nov, 2009 - 01:35 PM
Post #10

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 6

i entered it and it stills say that
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:36PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month