Jump to content

[SOLVED] Inserting data into 2 tables


mcgold652

Recommended Posts

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.

?>

Link to comment
https://forums.phpfreaks.com/topic/70817-solved-inserting-data-into-2-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.