1 form, 2 db tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kashmir
Forum Newbie
Posts: 6
Joined: Tue Nov 04, 2003 9:11 pm

1 form, 2 db tables

Post by kashmir »

Can someone tell me how I can insert records from one form into two different database tables on a submit? These tables are in the same database.

I would like to have one form that a visitor can create an account with a username and password which I would like into one table, and name, address, email, phone, into another database table.

I am not a hand coder so please be specific

Thanks! :?:
gbrussian
Forum Newbie
Posts: 3
Joined: Sun Nov 23, 2003 11:15 am

Post by gbrussian »

so basiclly your asking someone to create something for you???
kashmir
Forum Newbie
Posts: 6
Joined: Tue Nov 04, 2003 9:11 pm

Post by kashmir »

If I were, you probably wouldn't be my first choice.... But thanks anyway...
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

you mentioned your not a "hand coder", so what are you using to create this application? There are a couple of factors here like what database you are using but the most basic answer I can tell you right now is just do mulitple INSERT statments.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Sorry accidentally hit the wrong button on that last post I wasn't done.

So for example you want to input username and password into one table and users information into another table you could do something like ...

Code: Select all

<?php
// Create you INSERT Statements for each table from your variables
$sql = "INSERT INTO `access` ( `username` , `password`) VALUES ( 'Test', 'Test') ";
$sql2 = "INSERT INTO `info` ( `firstname` , `lastname`, `phonenumber`) VALUES ( 'John', 'Doe', '555-5555') ";
// Then Insert them
$result = mysql_query($sql) or die;
$result = mysql_query($sql2) or die;
?>
If you did something like this, you would more than likely want to marry the data up somehow. For example, in the sample given I would have grabbed the unique ID from the access table and added to my INSERT statement to the info table so I have a way of telling what username goes with which user.
kashmir
Forum Newbie
Posts: 6
Joined: Tue Nov 04, 2003 9:11 pm

Post by kashmir »

thank you mrvanjohnson...

Answer to your first post, I happily use Dreamweaver for my coding. Unfortunately the bad side is that's what keeps me in the dark as far as learning PHP. And this is the scenario that I wish I did know how to hand code... Oh, I think you asked what kind of database I'm using? It's MySQL

I think I *kind of* understand that example code you wrote, thank you for that. However I do not understand where you wrote VALUES ( 'John' 'Doe' etc....). Is that just an example for what its going to get? I guess I mean obviously this will be blank since those values are unknown?... Sorry, just trying to understand what you wrote and how to implement it. So is that all there is to it?

Thanks again
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Yeah, the values I used are just examples.

I use Dreamweaver as well, unfortunately I do most of my coding by hand so I'm not 100% sure if I remember how Dreamweaver does everything but I am 98% sure you can tell Dreamweaver to insert into 2 different tables using the Server Behaviors. Sorry I can't be of more help there but from what I remember, it's pretty intuitive if you already understand how to use the server behaviors. Again, these are only good on simplistic scenarios so I don't really use them at all any more.

Depending on what it is you are actually trying to accomplish, you might want to take the time to learn how to do this by hand. Database manipulation is one of the more basic function of PHP and a great starting point into really learning the language. Once you learn how much flexibility you have hand coding your database stuff you will probably never go back.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

kashmir wrote:If I were, you probably wouldn't be my first choice.... But thanks anyway...
uhh.. i think he was just asking, not offering, as this isn't the place to ask for scripts to be written for you.. no need to be rude
Post Reply