damonlee Posted November 8, 2003 Share Posted November 8, 2003 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) Quote Link to comment https://forums.phpfreaks.com/topic/1321-newbie-insert-into-two-tables-simutaneously/ Share on other sites More sharing options...
mad3533 Posted November 8, 2003 Share Posted November 8, 2003 $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\')\"; Quote Link to comment https://forums.phpfreaks.com/topic/1321-newbie-insert-into-two-tables-simutaneously/#findComment-4376 Share on other sites More sharing options...
Barand Posted November 8, 2003 Share Posted November 8, 2003 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] Quote Link to comment https://forums.phpfreaks.com/topic/1321-newbie-insert-into-two-tables-simutaneously/#findComment-4382 Share on other sites More sharing options...
damonlee Posted November 8, 2003 Author Share Posted November 8, 2003 This seems like it would be such a basic function....sheesh....gonna buy the freakn book... Quote Link to comment https://forums.phpfreaks.com/topic/1321-newbie-insert-into-two-tables-simutaneously/#findComment-4383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.