Forum Moderators: open

Message Too Old, No Replies

MySql table joining or PHP Form Multiple posting

ONe form posting to multiple tables

         

a4hiwayman

3:03 pm on Aug 20, 2009 (gmt 0)

10+ Year Member



Hi, a newbie to the forum and PHP coding.

I have two applications on one site that use PHP and MySql, one a bulletinboard and one a gallery. Both have separate logins and registration forms. I am looking to use the more comprehensive registration form for both sites. So visitors only have to register once.
I have imported the tables from the one database in to the other so I now have a single database with multiple registration tables.
Unfortunately the tables have different names:

Table1 (Members)
password
*no entry*
email
added
status
displayname

Table2 (users)
user_password
user_nicename
user_email
user_registered
user_status
user_displayname

Would I be better off using the 'JOIN' (or similar) statement to link the tables or would the easier approach be to use PHP? within the form to post a single entry to the relevant fields in the two tables?

Many thanks for your help in advance.
Gavin

rocknbil

4:21 pm on Aug 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard a4hiwayman, why can't you just do a switch based on the application being requested?

$bb = 'bulletin_board.php';
$gallery = 'gallery.php';

// Set $current_script based on some environment variable:
// $ENV['QUERY_STRING'], request file name, whatever
// what works best will depend on your environment (mostly)
// What you are after is $current_script == $bb/$gallery
// I use preg_match for case insensitivity, you could
// just do ==

$login_table = (preg_match("/$bb/i",$current_script))?'Members':'users';

Then replace "from table" with from $login_table:

$query = "select * from $login_table where....";

a4hiwayman

10:26 am on Sep 7, 2009 (gmt 0)

10+ Year Member



Hi Rocknbil,
thanks for your response. I am little confused how or where I'd use the 'switch'.

The plan is to have a single 'Regsition' and a sperate 'login' page which would then give them access to any area/application on the site.
Would the swith be used on the registration page when posting the form to insert the data into the relevant table for each app? I then assume that the code for checking if a member is already signed in would then look into it's own table to see if the user is flagged..... I assume I was also need to use the switch on the 'single' login page as well to flag the user account in each corresponding application table when they sign in?

Many thanks in advance for any advice.