This topic is locked

Inserting the username in additional tables

3/1/2006 20:07:56
PHPRunner General questions
K
ke5rs author

Hello support,

I am tiring to insert the username into two other tables in my database on a successful registration using the global events feature in PHP Runner, I did the following and I tried the word 'TEST' added fine in the two tables. When I replace 'TEST' with '$strUsername' ( I think $strUsername might be the variable for username) without quotes I get the error "Fatal error: Column count doesn't match value count at row 1 in /var/www/html/aresbeta/regestered/include/dbconnection.php on line 26"
Is there a better way to do this?
The following code is what I did to get 'TEST' into the fields 'Call' in both tables 'equipment' & 'training' without any errors.
function AfterSuccessfulRegistration()

{

//** Insert a record into another table ****

global $conn;

$strSQLInsert1 = "insert into training (Call) values ('TEST')";

$strSQLInsert2 = "insert into equipment (Call) values ('TEST')";
db_exec($strSQLInsert1,$conn);

db_exec($strSQLInsert2,$conn);
}
The following code returns the error on line 26 noted above...
function AfterSuccessfulRegistration()

{

//** Insert a record into another table ****

global $conn;

$strSQLInsert1 = "insert into training (Call) values ($strUsername)";

$strSQLInsert2 = "insert into equipment (Call) values ($strUsername)";
db_exec($strSQLInsert1,$conn);

db_exec($strSQLInsert2,$conn);
}
Thank you

Sergey Kornilov admin 3/2/2006

Hi,
this error appears because you try to insert undefined value strUsername.

To get value of entered username you can add some code to Before registration event on the Events Tab:

function BeforeRegister($userdata)

{

print_r($userdata);

$_SESSION["username"] = $userdata["FirstName"];

return true;

}



where FirstName is actually field name in your table.

Don't forget that this field name is case sensitive.
Then make some changes in After Success Registration event. Please see my changes in Bold:

function AfterSuccessfulRegistration()

{

global $conn;

$strSQLInsert1 = "insert into training (Call) values ('".$_SESSION["username"]."')";

$strSQLInsert1 = "insert into equipment (Call) values ('".$_SESSION["username"]."')";
db_exec($strSQLInsert1,$conn);

db_exec($strSQLInsert2,$conn);
}