mcgold652 Posted September 26, 2007 Share Posted September 26, 2007 Hi, I've checked the postings on this topic, tried some of the code, but I think I'm having a real block on figuring this out. I'm trying to insert data from a form into 2 tables, and I just can't find out whats the matter with this. The following is the insert function, which works fine inserting into the product table, just no information goes into the track table from the form. Any help would be greatly appreciated. require_once ('mysql_connect.php'); // Connect to the db. // Make the query. $prodQuery = "INSERT INTO products (artistName, title, tracks, refUPC, masterOwner, pLine, cLine, relTerr, configType, retPrice, genre, user_id) VALUES ('$an', '$tl', '$tr', '$up', '$mo', '$pl', '$cl', '$rt', '$cf', '$rp', '$ge', '$_SESSION')"; $prodResult = @mysql_query ($prodQuery); // Run the query. if ($prodResult) { // If it ran OK. // Send an email, if desired. // Print a message. echo '<h1 id="mainhead">Thank you!</h1><p>Your release has been sucessfully added to the AMP database.</p><p><br /></p>'; // Include the footer and quit the script (to not show the form). include ('footer.html'); exit(); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">Your product could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. include ('footer.html'); exit(); } $trackQuery = "INSERT INTO tracks (artistName, trackname) VALUES ('$an', '$tn')"; $trackResult = @mysql_query ($trackQuery); // Run the query. if ($trackResult) { // If it ran OK. // Send an email, if desired. // Print a message. echo '<h1 id="mainhead">Thank you!</h1><p>Your track has been sucessfully added to the AMP database.</p><p><br /></p>'; // Include the footer and quit the script (to not show the form). include ('footer.html'); exit(); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">Your track could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. include ('footer.html'); exit(); } mysql_close(); // Close the database connection. } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of the main Submit conditional. ?> Quote Link to comment https://forums.phpfreaks.com/topic/70817-solved-inserting-data-into-2-tables/ Share on other sites More sharing options...
BlueSkyIS Posted September 26, 2007 Share Posted September 26, 2007 Change this: $trackResult = @mysql_query ($trackQuery); to this: $trackResult = mysql_query ($trackQuery) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/70817-solved-inserting-data-into-2-tables/#findComment-356048 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.