This topic is locked

how to add records to table after successful registration

3/19/2016 6:52:11 PM
PHPRunner General questions
A
aaronc author

Hi!
I wish to add the RegID from my "users" table to new records on 5 other tables' RegID after successful user registration. This is for the purpose of auto generating new records in the 5 tables associated with the same RegID.
My users table fields are RegID (Primary), userID, password, username and email.
My code is as follows:
function AfterSuccessfulRegistration($userdata, $pageObject)

{
global $conn;

$str = "select RegID from users where userID='".$_SESSION["userID"]."'";

$rs = db_exec($str,$conn);

$data = db_fetch_array($rs);

$datains = $data["RegID"];

$strSQLInsert1 = "insert into applicant (RegID) values ($datains)";

db_exec($strSQLInsert1,$conn);

}
I got this error:
Technical information

Error type 256

Error description Column count doesn't match value count at row 1

URL localhost/admit/register.php?

Error file C:\xampp\htdocs\admit\connections\MySQLiConnection.php

Error line 142

SQL query insert into applicant (RegID) values ()
Any help will be appreciated!!

L
laonian 3/19/2016

Try to change this line:

$rs = db_exec($str,$conn);


to

$rs = db_query($str,$conn);


Also check if your table applicant has other fields that can't be null but have no default values assigned, besides RegID.

Admin 3/20/2016

According to what I see here is your SQL query:

insert into applicant (RegID) values ()


Values list is empty which means $data["RegID"] variable is empty, probably your first SQL query is incorrect and doesn't return any data. I have also add that $_SESSION["userID"] is incorrect while $_SESSION["UserID"] is correct.