3 Replies - 189 Views - Last Post: 10 January 2020 - 05:56 AM Rate Topic: -----

#1 lakp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-January 20

Insert Error Logs on registration failures to a table in PHP

Posted 10 January 2020 - 12:08 AM

I am modifying a system, where I need to add error log on registration failures when existing e-mail found, existing National Identity card(NIC) found and in captcha failures. To insert error log records, going to use the table z_error_log. I think this need to be done in the "else" part of the Vendor_cont.php file. Currently this provides an error messgae if an existing e-mail is used. I need to send that error log to the db. This is the code and I really appreciate your help as I am getting stuck on this point. Thanks in advance.

I added the PHPFILE.php file which contains both Vendor_cont.php and Log_model.php with relevant functions.

Is This A Good Question/Topic? 0
  • +

Replies To: Insert Error Logs on registration failures to a table in PHP

#2 lakp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-January 20

Re: Insert Error Logs on registration failures to a table in PHP

Posted 10 January 2020 - 12:18 AM

View Postlakp, on 10 January 2020 - 12:08 AM, said:

I am modifying a system, where I need to add error log on registration failures when existing e-mail found, existing National Identity card(NIC) found and in captcha failures. To insert error log records, going to use the table z_error_log. I think this need to be done in the "else" part of the Vendor_cont.php file. Currently this provides an error messgae if an existing e-mail is used. I need to send that error log to the db. This is the code and I really appreciate your help as I am getting stuck on this point. Thanks in advance.

I added the PHPFILE.php file which contains both Vendor_cont.php and Log_model.php with relevant functions.



This is my attached file.



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

=================Log_model.php========================



public function createErrorLog($user,$function,$error_data,$data){

        $ip=$_SERVER['REMOTE_ADDR'];
        $browser_os=  $_SERVER['HTTP_USER_AGENT'];
    $data= (array) $data_obj;

    //print_r($data);

    if (is_array($data)) {
        $val = '(' . implode(',', array_keys($data)) . ')';
        $val .= '=(' . implode(',', $data) . ')';
    } else {
        $val = $data;
    }

    $oStmt= $this->oDb->prepare('INSERT INTO z_error_log (`row_id`,`user`,`ip`,`page`,`function`,`data`,`browser_os`) VALUES (:row_id,:user,:ip,:page,:function,:data,:browser_os)');
    $oStmt->bindParam(':row_id', $row_id, \PDO::PARAM_INT);
    $oStmt->bindParam(':user', $user, \PDO::PARAM_INT);
    $oStmt->bindParam(':ip', $ip, \PDO::PARAM_STR);
    $oStmt->bindParam(':page', $page1, \PDO::PARAM_STR);
    $oStmt->bindParam(':function', $page_url, \PDO::PARAM_STR);
    $oStmt->bindParam(':data', $val, \PDO::PARAM_STR);
    $oStmt->bindParam(':browser_os', $browser_os, \PDO::PARAM_STR);
    $oStmt->execute();

    return  $this->oDb->lastInsertId();
}

This post has been edited by astonecipher: 10 January 2020 - 08:19 AM
Reason for edit:: code tags

Was This Post Helpful? 0
  • +
  • -

#3 lakp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-January 20

Re: Insert Error Logs on registration failures to a table in PHP

Posted 10 January 2020 - 12:29 AM

===================================Vendor_cont.php=============================

if($responseKeys['success']){
                    if(EMPTY( $checked_nic= $this->CModel->check_email($email) )){
                        if(EMPTY( $this->CModel->check_nic($nic) )){
                            $userData = array(
                                'user_role'=>'2',
                                'email' => $email,
                                'nic' => $nic,
                                'password' =>$password,
                                'payment' =>0,
                                'reg_date' =>date('Y-m-d H:i:s')
                            );

                            if ($inserted_user_id= $this->CModel->add_payment_user($userData)){

                                $this->LModel->createLog( $inserted_user_id,$inserted_user_id,'Vendor_cont/register_vendor- add main user',$userData,$_SERVER['PHP_SELF']); //create log

                                $number_type = 'V';
                                $group_label = 'VENDOR';

                                $autoNumberData = array(
                                    'number_type' => $number_type,
                                    'group_label' => $group_label
                                );

                                if ($inserted_auto_number_id = $this->CModel->add_auto_number($autoNumberData)) {

                                    $this->LModel->createLog($inserted_auto_number_id, $inserted_auto_number_id, 'Vendor_cont/register_vendor- add auto number', $autoNumberData, $_SERVER['PHP_SELF']); //create log

                                    while (strlen($inserted_auto_number_id) < 6) {
                                        $inserted_auto_number_id = "0" . $inserted_auto_number_id;
                                    }

                                    $registration_no = $number_type . $inserted_auto_number_id;

                                $venData = array(
                                    'user_id'=>$inserted_user_id,
                                    'registration_no' => $registration_no,
                                    'business_type'=>$business_type,
                                    'business_name'=>$business_name,
                                    'street' => $street,
                                    'street_line2' => $street_line2,
                                    'city' => $city,
                                    'state' => $state,
                                    'country' => $country,
                                    'phone' => $phone,
                                    'website' => $website,
                                    'business_reg_no' => $business_reg_no,
                                    'business_reg_authority' => $business_reg_authority,
                                    'value_of_proc_of_interest_rad_value' => $value_of_proc_of_interest_rad,
                                    'value_of_proc_of_interest' => $value_of_proc_of_interest
                                );

                                if ($inserted_id= $this->VModel->add_ven($venData)){

                                    $this->LModel->createLog( $inserted_id,$inserted_user_id,'Vendor_cont/register_vendor- add vendor',$venData,$_SERVER['PHP_SELF']); //create log

                                   //code
                                        $this->LModel->createLog( $inserted_V,$inserted_user_id,'Vendor_cont/register_vendor- add_vendor_nature_of_the_bsns',$aData,$_SERVER['PHP_SELF']); //create log
                                    }

                                    if(isset($_POST['dist_arr'])){
                                       code
                                    }

                                    if(isset($_POST['city_arr'])){
                                       //code

                                    }

                                    //upload documents
                                    $upload_path='uploads/vendor_documents/';
                                    // Count total files
                                    $countfiles = count($_FILES['file_input']['name']);
                                    // Looping all files
                                    for($i=0;$i<$countfiles;$i++){
                                        //code
                                    }

                                    //$this->LModel->createLog( $inserted_id,$inserted_user_id,'Vendor_cont/register_vendor-POST',$_POST,$_SERVER['PHP_SELF']); //create log

//                                    $_SESSION['Smessages'] = '<h3> Thank you very much for registration as a Vendors with  System . Please check your email given in your application for official acknowledgement and password generated by the  system.
//                                      You may please login to the System using the password input the information requested.
//                                       ! </h3>';

                                    //send mail that use login to pay
                                    $mail_sub='Temporary Login Details ';

                                    $mail_body=" "; //content of the body

                                    if( $this->mailModel->send_mail($email,$mail_sub,$mail_body)){
                                        $status=1;
                                    }else{
                                        $status=0;
                                    }
                                    $this->LModel->mail_log($inserted_user_id, $mail_body,"User Password",__METHOD__,$status,$email); //create log

                                    $_SESSION['Smessages'] = 'Registration Success. Pay the Registration fee to continue';

                                    header("Location:".ROOT_URL."?p=payment_cont&a=vendor_reg_fee&id=".$this->CModel->encode($inserted_user_id));
                                    die();

                                } else{
                                    $_SESSION['Emessages'] = 'An error has occurred! Please try again later.'; //set Error message
                                }
                                } else {
                                    $_SESSION['Emessages'] = 'An error has occurred! Please try again later.'; //set Error message
                                }

                            }else{
                                $_SESSION['Emessages'] = 'An error has occurred during user registration! Please try again later.'; //set Error message
                            }
                        }

                    }else{
                        //check whether paid fee or not
                        $paid= $this->UserModel->get_user_data($checked_nic->user_id);
                        if($paid->payment =='0'){
                            //didnt pay.
                            $_SESSION['Smessages'] = 'Registration Success. Pay the Registration fee to continue';
                            header("Location:".ROOT_URL."?p=payment_cont&a=vendor_reg_fee&id=".$this->CModel->encode($checked_nic->user_id));
                        }

                        if($paid->confirmed =='0' && $paid->payment =='1'){
                            //didnt pay.
                            $_SESSION['Emessages'] = 'Your information has been received.   
                           e-Gp system administrator will check your registration documents and will send you a new login credentials to your given email.';
                        }

                        if(($paid->confirmed =='1' && $paid->payment =='1') || $paid->payment =='2'){
                            //didnt pay.
                            $_SESSION['Emessages'] = ' Given E-mail already exists in the System. ';
                        }

                    }
                } else {
                     $_SESSION['Emessages'] = 'Recaptcha Failed. Please try again later';
                    // $this->LModel->createErrorLog(0,'Vendor_cont/register_vendor/recaptcha_fail',$responseKeys['success'],$_POST); //create log
                }
            }else{
                $_SESSION['Emessages'] = 'Captcha Required';
            }
        }

      //code
    }

This post has been edited by astonecipher: 10 January 2020 - 08:19 AM
Reason for edit:: removed unnecessary previous quotes code tags

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6833
  • View blog
  • Posts: 28,342
  • Joined: 12-December 12

Re: Insert Error Logs on registration failures to a table in PHP

Posted 10 January 2020 - 05:56 AM

There is no need to keep quoting previous posts, there is a Reply button further down the page.

Please wrap your code in code tags.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1