0

Here is the code. I have trouble with the registration process here. thanks anyway.

<?php
session_start();
include("connect.php");
$b_name = $_POST["txtbusinessname"];
$b_add = $_POST["txtbusinessadd"];
$email = $_POST["txtemailadd"];
$contact = $_POST["txtcontact"];
$cell = $_POST['txtcontact'];

$_SESSION["bname"]= $b_name;
$_SESSION["badd"]= $b_add;
$_SESSION["bemail"]= $email;
$_SESSION["bcontact"]= $contact;
$_SESSION["cell"] = $cell;

$format_cell = "+639";

if($b_name=="")
{
    echo("<script>alert('Business Name is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}
else if($b_add=="")
{
    echo("<script>alert('Business Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}

else if(!isValidEmail($email))
{
    echo("<script>alert('Email address is invalid')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return; 
}

else if($email=="")
{
    echo("<script>alert('Email Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}
else if($contact=="")
{
    echo("<script>alert('Email Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}

else if(strlen($cell) > 0)
{
    $temp_cell = substr($cell,0,4);
    if($temp_cell != $format_cell)
    {
        echo("<script>alert('Cellphone number format is incorrect')</script>");
            echo" <script>window.location=\"../index.php\";</script> ";   
        return;
    }
}

else {

$r = rand(10000, 1000000); 
$result = mysql_query("insert into tbl_client_master(b_name,b_address,email,contactno) values('$b_name','$b_add','$email','$contact')") or die(mysql_error());
$result2 = mysql_query("insert into tbl_users(username,password,role) values('$email','$r','Client')");



        $from = "********@gmail.com";
        $body = "Thank you for registering with us <br><br> Your password is: $r";

        $to = $email;
        $subject = 'Frontline Production: Registration Complete';

        $headers = "From: " . strip_tags('"********@gmail.com') . "\r\n";
        $headers .= "Reply-To: ". strip_tags('"********@gmail.com') . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";



        require_once("PHPMailer/class.phpmailer.php");
        define('GUSER', '**********@gmail.com'); // Gmail username
        define('GPWD', '**********'); 

        global $error;
            $mail = new PHPMailer();  // create a new object
            $mail->IsSMTP(); // enable SMTP
            $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
            $mail->SMTPAuth = true;  // authentication enabled
            $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 465; 
            $mail->Username = GUSER;  
            $mail->Password = GPWD;           
            $mail->SetFrom($from, "Frontline Production");
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($to);
            $mail->IsHTML(true);
            if(!$mail->Send()) {
                $error = 'Mail error: '.$mail->ErrorInfo; 
            } else {
                $error = 'Message sent!';
            }

/*SMS*/
$_objSmsProtocolGsm = new Com("ActiveXperts.SmsProtocolGsm");
$objMessage   = new Com ("ActiveXperts.SmsMessage");
$objConstants = new Com ("ActiveXperts.SmsConstants");

$objMessage->Recipient = $contact;
$objMessage->Format = $objConstants->asMESSAGEFORMAT_UNICODE;
$objMessage->Data = "Your password is: " . $r;
$_objSmsProtocolGsm->Device = "HUAWEI Mobile Connect - 3G Modem #2";
$_objSmsProtocolGsm->DeviceSpeed = 0;
if( $_objSmsProtocolGsm->LastError == 0 ){
    $_objSmsProtocolGsm->Send( $objMessage );
}


    $_SESSION["bname"]= "";
    $_SESSION["badd"]= "";
    $_SESSION["bemail"]= "";
    $_SESSION["contact"]= "";

    echo("<script>alert('Registration Successful, Please check your email for your password')</script>");
    echo" <script>window.location=\"../index.php\";</script> ";   
}



?>

<?php

function isValidEmail($email){ 
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}
 ?>

Edited by JorgeM: Edited: masked username and password in code.

4
Contributors
8
Replies
36
Views
3 Years
Discussion Span
Last Post by jstfsklh211
0

It would be helpful if you can describe the actual problem you are having, and/or errors...

0
<?php
session_start();
include("connect.php");
$b_name = $_POST["txtbusinessname"];
$b_add = $_POST["txtbusinessadd"];
$email = $_POST["txtemailadd"];
$contact = $_POST["txtcontact"];

$_SESSION["bname"]= $b_name;
$_SESSION["badd"]= $b_add;
$_SESSION["bemail"]= $email;
$_SESSION["bcontact"]= $contact;

if($b_name=="")
{
    echo("<script>alert('Business Name is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}
if($b_add=="")
{
    echo("<script>alert('Business Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}

if(!isValidEmail($email))
{
    echo("<script>alert('Email address is invalid')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return; 
}

if($email=="")
{
    echo("<script>alert('Email Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}
if($contact=="")
{
    echo("<script>alert('Contact Address is required')</script>");
        echo" <script>window.location=\"../index.php\";</script> ";   
    return;
}

$r = rand(10000, 1000000); 
$result = mysql_query("insert into tbl_client_master(b_name,b_address,email,contactno) values('$b_name','$b_add','$email','$contact')") or die(mysql_error());
$result2 = mysql_query("insert into tbl_users(username,password,role) values('$email','$r','Client')");



        $from = "********@gmail.com";
        $body = "Thank you for registering with us <br><br> Your password is: $r";

        $to = $email;
        $subject = 'Frontline Production: Registration Complete';

        $headers = "From: " . strip_tags('********@gmail.com') . "\r\n";
        $headers .= "Reply-To: ". strip_tags('********@gmail.com') . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";



        require_once("PHPMailer/class.phpmailer.php");
        define('GUSER', '********@gmail.com'); // Gmail username
        define('GPWD', '********'); 

        global $error;
            $mail = new PHPMailer();  // create a new object
            $mail->IsSMTP(); // enable SMTP
            $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
            $mail->SMTPAuth = true;  // authentication enabled
            $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 465; 
            $mail->Username = GUSER;  
            $mail->Password = GPWD;           
            $mail->SetFrom($from, "Frontline Production");
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($to);
            $mail->IsHTML(true);
            if(!$mail->Send()) {
                $error = 'Mail error: '.$mail->ErrorInfo; 
            } else {
                $error = 'Message sent!';
            }

/*SMS*/
$_objSmsProtocolGsm = new Com("ActiveXperts.SmsProtocolGsm");
$objMessage   = new Com ("ActiveXperts.SmsMessage");
$objConstants = new Com ("ActiveXperts.SmsConstants");

$objMessage->Recipient = $contact;
$objMessage->Format = $objConstants->asMESSAGEFORMAT_UNICODE;
$objMessage->Data = "Your password is: " . $r;
$_objSmsProtocolGsm->Device = "HUAWEI Mobile Connect - 3G Modem #2";
$_objSmsProtocolGsm->DeviceSpeed = 0;
if( $_objSmsProtocolGsm->LastError == 0 ){
    $_objSmsProtocolGsm->Send( $objMessage );
}


    $_SESSION["bname"]= "";
    $_SESSION["badd"]= "";
    $_SESSION["bemail"]= "";
    $_SESSION["contact"]= "";

    echo("<script>alert('Registration Successful, Please check your email for your password')</script>");
    echo" <script>window.location=\"../index.php\";</script> ";   



?>

<?php

function isValidEmail($email){ 
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}
 ?>

Just a question right here. if the IF conditions are not fulfilled, will the code still execute to the sql tables? I'm just worried about the fact that there are no else statements.

Edited by JorgeM: Edited post, masked username and passwords...

0

So? Errors or not? You haven't stated a problem though, just asking a question. You need to test you code thoroughly with dummy data if need be...

e.g.

$b_name = '';
$b_add = '';
$email = '';
$contact = '';

under the post assignments (insert into line 9). Then change the values to see if the script (yours?) works as expected.

0

Hello SPRINGHEEL. Please... before you post your sample code for a 3rd time, you should consider not including your gmail username and password in the code. I've edited your posts twice already (you should have received a message from the system).

If you post your username and password for a 3rd time, you do so at your own risk from this point on.

0

Sorry for that. Promise it wont happen again

its not a problem for me... i'm just trying to help prevent a whole bunch of people gaining access to your credentials.

0

most likely your trying to use your session variable on the same page you are submitting them

you need to submit them and reload before you can access them from $_SESSION

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.