Jump to content


Photo

newbie-insert into two tables simutaneously?


  • Please log in to reply
3 replies to this topic

#1 damonlee

damonlee
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 08 November 2003 - 01:46 AM

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)

#2 mad3533

mad3533
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationCarefree, AZ, USA

Posted 08 November 2003 - 04:29 AM

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

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,020 posts

Posted 08 November 2003 - 08:40 AM

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]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 damonlee

damonlee
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 08 November 2003 - 02:06 PM

This seems like it would be such a basic function....sheesh....gonna buy the freakn book... 8)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users