Jump to content

Archived

This topic is now archived and is closed to further replies.

damonlee

newbie-insert into two tables simutaneously?

Recommended Posts

I\'m trying to insert into two tables from an html page with input text boxes...the results are then displayed on another page that takes the data from the two tables and diplays it. here is part of my code:

 

$sql = \"INSERT INTO personnel, (firstname, lastname, email, salary) VALUES (\'$first\', \'$last\', \'$nickname\',\'$email\',\'$salary\')\";

//$sql = \"INSERT INTO about, (aboutId, eyeColor, hairColor, height) VALUES (\'$aboutId\', \'$eyeColor\', \'$hairColor\',\'$height\')\";

$result = mysql_query($sql);

 

the second $sql is commented out, but thats what i\'m trying to solve. How to I get $result variable to have data from both tables assigned to it?($result)

Share this post


Link to post
Share on other sites

$sql = \\\"INSERT INTO personnel, (firstname, lastname, email, salary) VALUES (\'$first\', \'$last\', \'$nickname\',\'$email\',\'$salary\')\\\";

 

Shouldn\'t it be....

$sql = \"INSERT INTO personnel (firstname, lastname, nickname email, salary) VALUES (\'$first\', \'$last\', \'$nickname\', \'$email\', \'$salary\')\";

Share this post


Link to post
Share on other sites

In a nutshell, you can\'t.

 

You need to :-

 

insert the first record

Get the id of the inserted record

Set $aboutid to the same value

Insert the second

 

HINT- use[php:1:b7647c77a4]<?php

 

#if $conn is the resutl returned from mysql_connect()

 

$aboutid = mysql_insert_id($conn);

?>[/php:1:b7647c77a4]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.