Is There Any One Who Help Me Out with My PHP Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akvlko
Forum Newbie
Posts: 2
Joined: Sat Jan 16, 2010 1:23 am
Location: Lucknow [India]
Contact:

Is There Any One Who Help Me Out with My PHP Code

Post by akvlko »

Hi! Friends,
This is Ashok from India
As I'm a Beginner in PHP so I need your help to solve my Problem

My Code is here

Code: Select all

<?php
//All database connections are running Successfully
function validateEmail($email){
  $output = "This address may be valid.";   
  $email = trim($email);
  If ((strlen($email)<5) or strstr($email," ")){
    $output = "ERROR";
  }
  If (substr_count($email, "@")<>1){
    $output = "ERROR";
  }
  Else{ #it has an at,split into 2 halves on the @
    $halves=explode ("@", $email);
    If (strlen($halves[0])<1 or strlen($halves[1])<=3){
      $output = "ERROR";
    }
    If (substr($halves[0],0,1)=="." or substr($halves[0],-1,1)=="."){
      $output = "ERROR";
    }
    If (substr($halves[1],0,1)=="." or substr($halves[1],-1,1)=="."){
      $output = "ERROR";    
    }
    if (!strstr($halves[1],".") or strstr($halves[1],"..")){
      $output = "ERROR";
    }
  }
  return $output;
}
   
    $msg="";
    $fuid=$_POST['ruid'];
    $fpassword=$_POST['rpassword'];
    $cfpassword=$_POST['rcpassword'];
    $femail=$_POST['remail'];
    $ffname=$_POST['rfname'];
    $flname=$_POST['rlname'];
    $fcity=$_POST['rcity'];
    $fmobile=$_POST['rmobile'];
    $fsmsalert=$_POST['rsmsalert'];
    $gndr=$_POST['gndr'];
    
    if($fpassword!=$cfpassword)
        {
            $msg="<font color='red'><b>Error: </b> Password Does Not Match !</font>";
            header("location: index.php?msg=$msg");
            exit();
        }
    
    if(!$femail)
    {
        $msg="<font color='red'><b>Error: </b> Please Enter Your Email !</font>";
        header("location: index.php?msg=$msg");
        exit();
    }
    else
    {
        if(validateEmail($femail)=="ERROR")
        {
            $msg="<font color='red'><b>Error: </b> Invalid Email Address !</font>";
            header("location: index.php?msg=$msg");
            exit();
        }
        else
        {
 
                
                ///More Validation Gose Here
                
            if(!$fuid)
                {
                    $msg="<font color='red'><b>Error: </b> Please Enter a User Name !</font>";
                    header("location: index.php?msg=$msg");
                    exit();
                }
            else
                {
    
                    $qry="SELECT * FROM nonreg WHERE uid='$fuid'";
                    $result=mysql_query($qry);
        
                    if($result) 
                    {
                        if(mysql_num_rows($result) == 1) 
                        {
                            $msg="<font color='green'><b>$fuid</b> This Username Already Taken !</font>";
                            header("location: index.php?msg=$msg");
                            exit();
                        }
                    }
                    else //USern Name Not Taken
                    {
                        $qury="INSERT INTO `nonreg` 
                                (`id`, 
                                `uid`, 
                                `password`, 
                                `fname`, 
                                `lname`, 
                                `gender`, 
                                `email`, 
                                `mobile`, 
                                `landline`, 
                                `city`,
                                `country`,
                                `smsalert`)
                                VALUES 
                                ('',
                                '$fuid', 
                                '$fpassword', 
                                '$ffname', 
                                '$flname', 
                                '$gndr', 
                                '$femail', 
                                '$fmobile',
                                '', 
                                '$fcity', 
                                '', 
                                '$fsmsalert')";
                                
                            $r=mysql_query($qury);
                            if(!quury)
                            {
                                $msg="<font color='red'><b>ERROR:</b> Registraion Incomplete !</font>";
                                header("location: index.php?msg=$msg");
                                exit();
                            }
                            else
                            {
                                $msg="<font color='green'><b>Thank You!</b> Registed with Us!</font>";
                                header("location: youraccount.php?msg=$msg");
                                exit();
                            }                   
                
                    }
                }//End of Else UID
        }//End of Else validateEmail
    }//End of Else $femail          
?>
 
The Problem is this After Validation of Email
if Email is Wrong its Show an Error
but if it is right then My Page is being Empty No any Errors No any Other things


Please Help Me Out...!

Thanks in Advanced for Your Kind Support.

Contact:
Email: akvlko@in.com
ashok.it@versatilesolutions.info :cry: :cry:
Last edited by akvlko on Sat Jan 16, 2010 3:06 am, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Is There Any One Who Help Me Out with My PHP Code

Post by social_experiment »

Hello,

I don't see any attempt ( in the code ) where you try to send the email. If the code below is where you wish to send the email, you might have to change it slightly.

Code: Select all

 
<?php
 if(!quury)
{
$msg="<font color='red'><b>ERROR:</b> Registraion Incomplete !</font>";
header("location: index.php?msg=$msg");
exit();
}
else
{
$msg="<font color='green'><b>Thank You!</b> Registed with Us!</font>";
header("location: youraccount.php?msg=$msg");
exit();
} 
?>
 
You need to compile all the information you wish to send in the mail :


Code: Select all

 
<?php
 $to = "email@toSend.to";
 $message = "Information you want to send";
 $subject = "Subject of email";
 
 $emailVariable = @mail($to, $subject, $message);
 
 if (!$emailVariable) {
  // code displaying message indication email has not been sent.
 }
 else {
  // code indicating message has successfully been sent.
 }
?>
 
Hope this helps
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: Is There Any One Who Help Me Out with My PHP Code

Post by kalidG »

Code: Select all

 
if(!quury)
{
$msg="<font color='red'><b>ERROR:</b> Registraion Incomplete !</font>";
header("location: index.php?msg=$msg");
exit();
}
else
{
$msg="<font color='green'><b>Thank You!</b> Registed with Us!</font>";
header("location: youraccount.php?msg=$msg");
exit();
} 
 
i think you have some mistyping
you tested on !quury wich doesn't exist and you should test not on the query text but in the execution
and you affect thexecution of the query to $r
so you should do this
and don't miss the '$' (i miss it a lot lol)

Code: Select all

 
if(!$r)
{
$msg="<font color='red'><b>ERROR:</b> Registraion Incomplete !</font>";
header("location: index.php?msg=$msg");
exit();
}
else
{
$msg="<font color='green'><b>Thank You!</b> Registed with Us!</font>";
header("location: youraccount.php?msg=$msg");
exit();
} 
 
hope this help
best regards ,
Khaled Garbaya
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: Is There Any One Who Help Me Out with My PHP Code

Post by kalidG »

Code: Select all

 
$qury="INSERT INTO `nonreg`
(`id`,
`uid`,
`password`,
`fname`,
`lname`,
`gender`,
`email`,
`mobile`,
`landline`,
`city`,
`country`,
`smsalert`)
VALUES
('',
'$fuid',
'$fpassword',
'$ffname',
'$flname',
'$gndr',
'$femail',
'$fmobile',
'',
'$fcity',
'',
'$fsmsalert')";
i think too many quotes there try this:

Code: Select all

 
$qury="INSERT INTO `nonreg`
(`id`,
`uid`,
`password`,
`fname`,
`lname`,
`gender`,
`email`,
`mobile`,
`landline`,
`city`,
`country`,
`smsalert`)
VALUES
('$fuid' ,
'$fpassword' ,
'$ffname' ,
'$flname' ,
'$gndr' ,
'$femail' ,
'$fmobile' ,
'$fcity' ,
'$fsmsalert')";
 
try to echo out the query in the page to test if every things go well
it is a great way to know if parameters are passed correctelly or not
hope this help too
best regards ,
Khaled Garbaya
User avatar
akvlko
Forum Newbie
Posts: 2
Joined: Sat Jan 16, 2010 1:23 am
Location: Lucknow [India]
Contact:

Re: Is There Any One Who Help Me Out with My PHP Code

Post by akvlko »

Code: Select all

if(validateEmail($femail)=="ERROR")
        {
            $msg="<font color='red'><b>Error: </b> Invalid Email Address !</font>";
            header("location: index.php?msg=$msg");
            exit();
        }
 
 
This Section is going Well and when this Condition is False The page is Left Blank
I'm not able to understand what is going on
even I checked my All code step by step
I delete the unnecessary codes
but it still not working?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Is There Any One Who Help Me Out with My PHP Code

Post by social_experiment »

Code: Select all

 
<?php
 if(validateEmail($femail)=="ERROR")
         {
             $msg="<font color='red'><b>Error: </b> Invalid Email Address !</font>";
             header("location: index.php?msg=$msg");
             exit();
         }
?>
 
Is 'validateEmail()' a custom function you created? If it's not working it could be the error code that you are returning, does not match 'ERROR'.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Is There Any One Who Help Me Out with My PHP Code

Post by social_experiment »

Code: Select all

 
<?php
    function ValidateEmail($email) {
        $email = trim($email);
        
        $haystack = '/^[\w.-]+@[\w-]{2,}+[\.A-Za-z]{2,}$/';
        $matchString = preg_match($haystack, trim($email), $matches);
        
        if (!$matchString) {
            return 'ERROR';
        }
        else {
            return 'VALID';
        }
    }
    
    if (validateEmail('emailAddyToTest') == 'ERROR') {
        echo 'ERROR';
    }
    else {
        echo 'Valid Email addy format';
    }  
?>
 
Try the above function for checking the valid format of an email address.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply