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) 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\')\"; 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] 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... 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
Archived
This topic is now archived and is closed to further replies.