Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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