This topic is locked

A couple of questions

2/5/2007 9:57:36 AM
PHPRunner General questions
I
ictaylor author

Hi, I have a couple of questions I hope you can help me with:
I have a website, for which to register you have to choose a username, password and state your email address and date of birth. On clicking register I want three of these four bits of information to be entered into another table which is the user table for my forum. Phprunner has suggested the following code:

function AfterSuccessfulRegistration()

{

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

global $conn;

$strSQLInsert = "insert into TableName (Field1, Field2) values (Value1, Value2)";

db_exec($strSQLInsert,$conn);
}


I am not sure what to edit here. Do I need to substitute 'TableName' with that of the table name I want to enter into?

Also what do I put for FIeld 1 and Field 2 etc and for Value1 and Value2?
My registration page asks users to give the four things listed above from which I want to input username, password and email address into the forum table (not date of birth). But my forum table has about 25 different fields with username and password as fields 1 and 2 respectively but email address is about field 20 or something.
What do I need to do?

J
Jane 2/6/2007

Hi,
sure you need to replace TableName with your actual table name, Field1 and Field2 with your actual field names which you want to save in another table.

All registration info is in the $values array.

Here is a sample code:

function AfterSuccessfulRegistration()

{

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

global $conn;

$strSQLInsert = "insert into TableName (Field1, Field2, Field3) values ('".$values["Field1"]."', '".$values["Field2"]."', '".$values["Field3"]."')";

db_exec($strSQLInsert,$conn);
}

I
ictaylor author 2/6/2007

Hi
I still can't get this to work and get a database error. This is the code I am using:

function AfterSuccessfulRegistration()

{

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

global $conn;

$strSQLInsert = "insert into phpbb1_users (Username, Password, Email Address) values ('".$values["username"]."', '".$values["user_password"]."', '".$values["user_email"]."')";
db_exec($strSQLInsert,$conn);
}


The table that users register into is called 'users' and has the fields 'Username', 'Password' and 'Email Address'. The table I want to transfer this data into is called 'phpbb1_users' with the relevant fields called 'username', 'user_password' and 'user_email'
I have tried the code with 'Username' 'Password' and 'Email Address' in both the field name and value name as well but it still doesnt work.
What am I doing wrong?

J
Jane 2/6/2007

Hi,
here is the correct code:

function AfterSuccessfulRegistration()

{

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

global $conn;

$strSQLInsert = "insert into phpbb1_users (username, user_password, user_email) values ('".$values["Username"]."', '".$values["Password"]."', '".$values["Email Address"]."')";
db_exec($strSQLInsert,$conn);
}

I
ictaylor author 2/6/2007

I am still getting an error using that above
'php error happened'
I have PM'd you an address where you can see this happening!

I
ictaylor author 2/6/2007

Do you think I need to send the 'ID Number' accross with the other info or am I clutching at straws?

J
Jane 2/6/2007

Sorry for my fault. Here is the correct code:

function AfterSuccessfulRegistration()

{

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

global $conn,$values;

$strSQLInsert = "insert into phpbb1_users (username, user_password, user_email) values ('".$values["Username"]."', '".$values["Password"]."', '".$values["Email Address"]."')";
db_exec($strSQLInsert,$conn);
}

I
ictaylor author 2/6/2007

Hi
Sorry to keep hassling you but I get the follwing php error with your latest code:

Error type 256

Error description Duplicate entry '0' for key 1

URL www.boxedclever.net/users/register.php?

Error file /home/b/o/boxedclever_net/users/include/dbconnection.php

Error line 26

SQL query insert into `_users` (`Username`, `Password`, `Email Address`, `Date Of Birth`) values ('test', 'a07ea7137bcaf427f935bdbed8369eb8', 'test@test.co.uk', '01/01/1901')

Solution It seems that you add duplicate key fields.
Please check data you enter on the ADD or REGISTER page.

J
Jane 2/7/2007

This error means that you add the record with duplicate primary key. You can do the following:

  • add primary key on the Register page and fill it with unique value
  • or set up primary field as auto-increment field in the database directly.

I
ictaylor author 2/7/2007

The _users table already has a primary INT key which is set to auto increment??

J
Jane 2/7/2007

Did you set up primary field as auto-increment in both tables?

I
ictaylor author 2/7/2007

I have set up the _users table to auto increment using phprunner. The forum table phpbb1_users wasnt created in phprunner and phprunner doesnt give me the option to modify it.
The phpbb1_users table was created by installing phpbb bulletin board and I assume it would auto increment. I realise phpbb support isnt your job! but it is the phprunner side of things I am trying to edit to do this.

Alexey admin 2/7/2007

Hi,
you can modify phpbb1_users table using any MySQL management tool, i.e. phpMyAdmin.

Add auto_increment attribute to phpbb1_users primary key field.
However I suppose that adding phpbb users is a more complex procedure than just adding a record to phpbb1_users table.

So there is no guarantee that this will work.