Jump to content

- Help -


ChompGator

Recommended Posts

>:(

 

Hey, Ive made a simple registration form, which submits and sends that person an email with a validation link -

 

When visiting the URL where my form is, Im getting a parse error on line 5 - So here is my registration form, and I have a 'include('functions.php') as well - so I posted both scrips, tell me what you see wrong :( I unfortunately dont see anything wrong:

registration.php

<?php   
require_once('db.php');
include('functions.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 jetblue (`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: [email protected]' . "\r\n" .  
                            'Reply-To: [email protected]' . "\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']."&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>   
<? } ?> 

 

 

Functions.php

<?php 
function EmailValidation($email) {  
    $email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits 
     
    if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format 
    $domain = explode( "@", $email ); //get the domain name 
         
        if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) { 
            //if the connection can be established, the email address is probabley valid 
            return true; 
            /* 
             
            GENERATE A VERIFICATION EMAIL 
             
            */ 
             
        } else { 
            return false; //if a connection cannot be established return false 
        } 
     
    } else { 
        return false; //if email address is an invalid format return false 
    } 
} 
?> 

Link to comment
https://forums.phpfreaks.com/topic/81074-help/
Share on other sites

Hello,

 

I have this registration script Im playing with, and Im getting a parse error on line 5, and Ill post the error below, also below is my script.

I was wondering if someone could see the error on my line 5.

Parse error: parse error, unexpected ';' in D:\hosting\member\aiim\site2\testing\registration.php on line 5

 

All the  ';'  I see on my line 5, belong there :(

 

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

if($_GET['ID']!='' && numeric($_GET['ID'])==TRUE && strlen($_GET['key'])==32 && alpha_numeric($_GET['key'])==TRUE)
{

	$query = mysql_query("SELECT ID, Random_key, Active FROM jetblue WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'");

	if(mysql_num_rows($query)==1)
	{
		$row = mysql_fetch_assoc($query);
		if($row['Active']==1)
		{
			$error = 'This member is already active !';
		}
		elseif($row['Random_key']!=$_GET['key'])
		{
			$error = 'The confirmation key that was generated for this member does not match with the one entered !';
		}
		else
		{
			$update = mysql_query("UPDATE jetblue SET Active=1 WHERE ID='".mysql_real_escape_string($row['ID'])."'") or die(mysql_error());
			$msg = 'Congratulations !  You just confirmed your membership !';
		}
	}
	else {

		$error = 'User not found !';

	}

}
else {

	$error = 'Invalid data provided !';

}

if(isset($error))
{
	echo $error;
}
else {
	echo $msg;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/81074-help/#findComment-411627
Share on other sites

Ok, my bad, here are my errors, I fixed some but I got more, this is on my fuctions page,

 

Warning: Missing argument 3 for checkUnique(), called in D:\hosting\member\aiim\site2\testing\registration.php on line 7 and defined in D:\hosting\member\aiim\site2\testing\functions.php on line 7

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\testing\functions.php on line 10

 

Warning: Missing argument 3 for checkUnique(), called in D:\hosting\member\aiim\site2\testing\registration.php on line 7 and defined in D:\hosting\member\aiim\site2\testing\functions.php on line 7

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\testing\functions.php on line 10

Unknown column 'Email' in 'field list'

 

Here is the registration page code

<?php   
require_once('db.php');   
include('functions.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 jetblue (`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: [email protected]' . "\r\n" .  
                            'Reply-To: [email protected]' . "\r\n" .  
                            'X-Mailer: PHP/' . phpversion();  
                $subject = "Activation email from JetBlue Virtual";  
                $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']."&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 the script from my functions.php page

 

<?php
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}

function checkUnique($table, $field, $compared)   
{   
    $query = mysql_query('SELECT  '.mysql_real_escape_string($field).' FROM '.mysql_real_escape_string($table).' WHERE "'.mysql_real_escape_string($field).'" = "'.mysql_real_escape_string($compared).'"');   
    if(mysql_num_rows($query)==0)   
    {   
        return TRUE;   
    }   
    else {   
        return FALSE;   
    }   
} 
function random_string($type = 'alnum', $len =    
{                      
    switch($type)   
    {   
        case 'alnum'    :   
        case 'numeric'  :   
        case 'nozero'   :   
           
                switch ($type)   
                {   
                    case 'alnum'    :   $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';   
                        break;   
                    case 'numeric'  :   $pool = '0123456789';   
                        break;   
                    case 'nozero'   :   $pool = '123456789';   
                        break;   
                }   
  
                $str = '';   
                for ($i=0; $i < $len; $i++)   
                {   
                    $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);   
                }   
                return $str;   
          break;   
        case 'unique' : return md5(uniqid(mt_rand()));   
          break;   
    }   
}  
?> 

Link to comment
https://forums.phpfreaks.com/topic/81074-help/#findComment-411636
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.