I am using array where I insert data to a table call z_error_log. These inserted data gives me an output as follows in the table under the column 'data'.
(user_role,email,nic,password,payment,reg_date)=(2,dfghjkbhjn@gmail.com,123456789045,$2y$10$R4MOTLHlhe1M9GCt0utxQO3d43oFrH.34ivCPPtHpral.cM/kW5sq,0,2020-01-13 14:44:27)
But What I actually need to do is, to insert those data to the table where it stored as follows.
user_role = 2,email=dfghjkbhjn@gmail.com,nic=123456789045,password=$2y$10$R4MOTLHlhe1M9GCt0utxQO3d43oFrH.34ivCPPtHpral.cM/kW5sq,payment,reg_date=2020-01-13 14:44:27
I need to assign the value right after its name as in the above.
Here I add the Part of the class Vendor_cont and function in the Log_model.php file where I use to enter data to the z_error_log table.
================Vendor_cont.php====================
class Vendor_cont
{
//CLASS Content
}
}
// ===================EDITED If Recaptcha Fail=====================================
else {
$userData = array(
'user_role'=>'2',
'email' => $email,
'nic' => $nic,
'password' =>$password,
'payment' =>0,
'reg_date' =>date('Y-m-d H:i:s')
);
$_SESSION['Emessages'] = 'Recaptcha Failed. Please try again later';
$this->LModel->createErrorLog(3,'Vendor_cont/register_vendor/recaptcha_fail',$email,$userData);
}
//========================================================================================
}
==================Log_model.php==================
public function createErrorLog($user,$function,$error_data,$data_obj){
$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;
}
// =============EDITED==============
$oStmt= $this->oDb->prepare('INSERT INTO z_error_log (`function`, `error_data`,`data`,`user` ,`ip`,`browser_os`) VALUES (:function,:error_data,:data,:user,:ip,:browser_os)');
$oStmt->bindParam(':function', $function, \PDO::PARAM_STR);
$oStmt->bindParam(':error_data', $error_data, \PDO::PARAM_STR);
$oStmt->bindParam(':data', $val, \PDO::PARAM_STR);
$oStmt->bindParam(':user', $user, \PDO::PARAM_INT);
$oStmt->bindParam(':ip', $ip, \PDO::PARAM_STR);
$oStmt->bindParam(':browser_os', $browser_os, \PDO::PARAM_STR);
$oStmt->execute();
return $this->oDb->lastInsertId();
}
I really appreciate your help. Thanks in advance.