Jump to content

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)

$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\')\";

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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.