This topic is locked

Registration page write to different table than users table

7/30/2019 9:46:15 AM
PHPRunner General questions
D
david22585 author

I was wondering if there was a way to send the information on the user registration page to a different table than the table that is used for login information? Lets say I have 2 tables, table 1 is "accounts_pending" and table 2 is "accounts_users". When someone registers, the data is sent to the "accounts_pending" table. Once an account is approved, the information is sent to the "accounts"users" table.
My reason for this is because every account has information stored on them in the "accounts_users" table, but not every account has a login to the website. When I was going to do was when I view the pending users in the separate table, I can select the account from the "accounts_users" table, and it will update that id number from that table with the information from the "accounts_pending" table. To give it more of a perspective, this is for a condo association where the board has an account under the "accounts_users" table with their name, contact information, account balance, etc. This is why every account doesn't have a login for it unless the co-owner wants to have access to the website. If they do decide to have access and create an account and its approved and put into the users table, they will have access to their balance and ability to update all their information that we have on them.
Or maybe someone else can think of a better way to create this setup or how to handle the situation like this?

Sergey Kornilov admin 7/30/2019

You can use an event like AfterSuccessfulRegistration to insert a record or records into another table.
More info:

https://xlinesoft.com/phprunner/docs/after_successful_registration.htm

https://xlinesoft.com/phprunner/docs/db_insert.htm

D
david22585 author 7/30/2019



You can use an event like AfterSuccessfulRegistration to insert a record or records into another table.
More info:

https://xlinesoft.com/phprunner/docs/after_successful_registration.htm

https://xlinesoft.com/phprunner/docs/db_insert.htm


I've tried 2 different variations of that. The first:

$data = array();

$data["fullname"] = $values["fullname"];

$data["email"] = $values["email"];

$data["password"] = $values["password"];

$data["address"] = $values["address"];

DB::Insert("accounts_pending", $data );


Enters everything as NULL in the accounts_pending table. The second one I tried:

$sql = "INSERT INTO accounts_pending (fullname, email, password, address) values

('".$values["fullname"]."','".$values["email"]."','".$values["password"]."','".$values["address"]."')";

DB::Query($sql);


Will insert blank data. Both create a new entry but neither one actually takes the data from the registration page and puts it into the table.

Sergey Kornilov admin 7/30/2019

AfterSuccessfulRegistration event doesn't have $values array defined and this is why you are getting an empty entry. You need to read the manual in order to see what you can use in that event:

https://xlinesoft.com/phprunner/docs/after_successful_registration.htm

D
david22585 author 7/30/2019



AfterSuccessfulRegistration event doesn't have $values array defined and this is why you are getting an empty entry. You need to read the manual in order to see what you can use in that event:

https://xlinesoft.com/phprunner/docs/after_successful_registration.htm


Thanks, I got that to work now but I'm now running into another issue. When trying to assign accounts, it won't push the right data when updating a table using the following code:

DB::Query("update accounts_values set unit=".$values["unit"].", building=".$values["building"].", address=".$values["address"].", linked='1' where id = ".$values["current_owner"]."" );


It seems where the issue is coming in is with the address, as it's a varchar field. The unit number, building number, and linked will all set correctly if I remove the address=".$values["address"].". When I add that back in, nothing will work at all. I tried to even do it separately, as below, and the unit, building, and linked all pushed correctly, but the address did not push. If I change the address field to an INT, it will work but there is text in the field that needs to get pushed as well.

DB::Query("update accounts_data set linked='1' where id = " . $values["current_owner"] . "" );

DB::Query("update accounts_data set unit=".$values["unit"]." where id = ".$values["current_owner"]."" );

DB::Query("update accounts_data set building=".$values["building"]." where id = ".$values["current_owner"]."" );

DB::Query("update accounts_data set address=".$values["address"]." where id = ".$values["current_owner"]."" );


THat will push the correct data/values where they need to go with the exception of address, which is the VARCHAR field. If I set address to not be a $value and just as 'Text Test', it works properly. But when it's set to read a value that is a VARCHAR, it won't work at all.
EDIT: If the table that it's reading from has any text in the VARCHAR field, it will not write that to the updated row. IF it's just a number, it will update the row. I've created a ticket and uploaded it to the demo site.

M
Mark Kramer 7/31/2019



Thanks, I got that to work now but I'm now running into another issue. When trying to assign accounts, it won't push the right data when updating a table using the following code:

DB::Query("update accounts_values set unit=".$values["unit"].", building=".$values["building"].", address=".$values["address"].", linked='1' where id = ".$values["current_owner"]."" );


It seems where the issue is coming in is with the address, as it's a varchar field. The unit number, building number, and linked will all set correctly if I remove the address=".$values["address"].". When I add that back in, nothing will work at all. I tried to even do it separately, as below, and the unit, building, and linked all pushed correctly, but the address did not push. If I change the address field to an INT, it will work but there is text in the field that needs to get pushed as well.

DB::Query("update accounts_data set linked='1' where id = " . $values["current_owner"] . "" );

DB::Query("update accounts_data set unit=".$values["unit"]." where id = ".$values["current_owner"]."" );

DB::Query("update accounts_data set building=".$values["building"]." where id = ".$values["current_owner"]."" );

DB::Query("update accounts_data set address=".$values["address"]." where id = ".$values["current_owner"]."" );


THat will push the correct data/values where they need to go with the exception of address, which is the VARCHAR field. If I set address to not be a $value and just as 'Text Test', it works properly. But when it's set to read a value that is a VARCHAR, it won't work at all.
EDIT: If the table that it's reading from has any text in the VARCHAR field, it will not write that to the updated row. IF it's just a number, it will update the row. I've created a ticket and uploaded it to the demo site.



On those fields that won't write, check the Validate As: and Mask: setting, Prevent duplicate values on the Edit as Field page/settings. Also make sure that it isn't set as a read only accidentally. Any of those can prevent it from saving the record.

D
david22585 author 8/1/2019



On those fields that won't write, check the Validate As: and Mask: setting, Prevent duplicate values on the Edit as Field page/settings. Also make sure that it isn't set as a read only accidentally. Any of those can prevent it from saving the record.


I've done it all. Using this code:

DB::Query("update accounts_data set address=".$values['address']." where id = ".$values["current_owner"]."" );


If the value of address on the edit page has any text at all on it, it will not write/update the information that corresponds to the ID in the accounts_data table. If it's a numerical value only, it will write. I've tried the following in the address field:
1 - Works

29119 - Works

a - Doesn't work. It will stay as the last numeric value, which would be 29119.

1a - Doesn't work. Stays as the last numeric value.

7897437894382934 - Works

1 - Works

Q - Doesn't work
For example:

address=".$values["address"]." = If the value of address is only a numerical value, it works

address=".$values["address"]." = If the value of address has any text in it or only text, doesn't work

address='Test Text' = This will work.
It only doesn't work for using text in a $values string.

Sergey Kornilov admin 8/3/2019

When you create your SQL query make sure you are adding single quotes around text and date values.