OOP PHP user class (usercake) not adding to database

I recently discovered that this small custom script class called usercake (http://usercake.com/) has all the basic functions and seems to work very well.

My problem . The first user is added to the database perfectly, but after that it does not work. It is clear that there is something a little wrong that I do not understand (I do not know oop php very well). Errors do not occur (I see), and the email is sent.

I have established several places with the same fate. I would like to fix this because using this script saves a lot of time on the ingenuity of the wheel.

Here is the URL where I have it: http://rawcomposition.com/birding/loggedin/register.php Here is the function that gets called when everything is checked:

public function userCakeAddUser() { global $db,$emailActivation,$websiteUrl,$db_table_prefix; //Prevent this function being called if there were construction errors if($this->status) { //Construct a secure hash for the plain text password $secure_pass = generateHash($this->clean_password); //Construct a unique activation token $this->activation_token = generateActivationToken(); //Do we need to send out an activation email? if($emailActivation) { //User must activate their account first $this->user_active = 0; $mail = new userCakeMail(); //Build the activation message $activation_message = lang("ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token)); //Define more if you want to build larger structures $hooks = array( "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"), "subjectStrs" => array($activation_message,$this->activation_token,$this->unclean_username) ); /* Build the template - Optional, you can just use the sendMail function Instead to pass a message. */ if(!$mail->newTemplateMsg("new-registration.txt",$hooks)) { $this->mail_failure = true; } else { //Send the mail. Specify users email here and subject. //SendMail can have a third parementer for message if you do not wish to build a template. if(!$mail->sendMail($this->clean_email,"New User")) { $this->mail_failure = true; } } } else { //Instant account activation $this->user_active = 1; } if(!$this->mail_failure) { //Insert the user into the database providing no errors have been found. $sql = "INSERT INTO `".$db_table_prefix."Users` ( `Username`, `Username_Clean`, `Password`, `Email`, `ActivationToken`, `LastActivationRequest`, `LostPasswordRequest`, `Active`, `Group_ID`, `SignUpDate`, `LastSignIn` ) VALUES ( '".$db->sql_escape($this->unclean_username)."', '".$db->sql_escape($this->clean_username)."', '".$secure_pass."', '".$db->sql_escape($this->clean_email)."', '".$this->activation_token."', '".time()."', '0', '".$this->user_active."', '1', '".time()."', '0' )"; return $db->sql_query($sql); } } } 

And here is the table structure:

 CREATE TABLE IF NOT EXISTS `userCake_Users` ( `User_ID` int(11) NOT NULL AUTO_INCREMENT, `Username` varchar(150) NOT NULL, `Name` varchar(100) NOT NULL, `Username_Clean` varchar(150) NOT NULL, `Password` varchar(225) NOT NULL, `Email` varchar(150) NOT NULL, `ActivationToken` varchar(225) NOT NULL, `LastActivationRequest` int(11) NOT NULL, `LostPasswordRequest` int(1) NOT NULL DEFAULT '0', `Active` int(1) NOT NULL, `Group_ID` int(11) NOT NULL, `SignUpDate` int(11) NOT NULL, `LastSignIn` int(11) NOT NULL, PRIMARY KEY (`User_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; 
+6
source share
3 answers

For me, there are two possibilities why it does not add new users after adding the first:

First, the flag $this->mail_failure is set to TRUE for the following user accounts after the first user is created. But this scenario is unlikely because it is the same code that was successfully run for the first user, and therefore there is no reason why the flag should be TRUE for others.

The second possibility is that $this->status is FALSE for the second user account. If false, the userCakeAddUser() method userCakeAddUser() nothing. The reasons this flag may be false is either a username or an email address already exists.

Are you using the same username or email address that was used for the first account for the second account? I am sure that you should not use the same username, but possibly the same email address. The usercake classes do not allow the same username or the same email addresses.

Hope this helps.

+2
source

I would do 4 things with this uggly code:

1) to enable error_reporting mode so you can see something in case sthg occurs:

  error_reporting(E_ALL); 

2) to check this INSERT sql directly to dB , to make sure that it works correctly, and confirm this piece of code. If the sql INSERT query is valid, check the access conditions for this SQL query, as Abhay said above,

3) Since we do not have your configuration available, playing guessing games is difficult. Therefore, I suggest you add one NULL field for AI User_ID.

 $sql = "INSERT INTO `".$db_table_prefix."Users` ( `User_ID`, // Add this here `Username`, `Username_Clean`, `Password`, `Email`, `ActivationToken`, `LastActivationRequest`, `LostPasswordRequest`, `Active`, `Group_ID`, `SignUpDate`, `LastSignIn` ) VALUES ( NULL, // and that one '".$db->sql_escape($this->unclean_username)."', '".$db->sql_escape($this->clean_username)."', '".$secure_pass."', '".$db->sql_escape($this->clean_email)."', '".$this->activation_token."', '".time()."', '0', // later, I would also try using an int for an int '".$this->user_active."', '1', '".time()."', '0' )"; 

4) to find another, better encoding using OOP and PDO.

+2
source

You gave Name as NOT NULL, and in the Insert statement of your code it does not send the name value, so mysql throws an exception saying that Name cannot be null, check it once.

0
source

Source: https://habr.com/ru/post/890525/


All Articles