Page 1 of 1

1 form, 2 db tables

Posted: Fri Nov 28, 2003 12:17 pm
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! :?:

Posted: Fri Nov 28, 2003 12:17 pm
by gbrussian
so basiclly your asking someone to create something for you???

Posted: Fri Nov 28, 2003 12:44 pm
by kashmir
If I were, you probably wouldn't be my first choice.... But thanks anyway...

Posted: Fri Nov 28, 2003 1:14 pm
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.

Posted: Fri Nov 28, 2003 1:24 pm
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.

Posted: Fri Nov 28, 2003 1:59 pm
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

Posted: Fri Nov 28, 2003 3:30 pm
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.

Posted: Fri Nov 28, 2003 7:53 pm
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