This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [SOLVED] Multiple INSERT INTO queries in one MySQL result  (Read 1754 times)

Cuana

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 9
    • View Profile
[SOLVED] Multiple INSERT INTO queries in one MySQL result
« on: August 11, 2013, 11:46:55 pm »
Hi,

I'm currently working on a CMS for the Trinity World DB. I'm kind of new to PHP/SQL and am seeking a simple explanation for executing multiple queries at once!

Currently I am able to insert data into the creature_template database using a HTML form. This works fine as there's only one table where data needs to be inputed.

However when it comes to quests - i have no problem entering data into the quest_template table. However in order to link the quest to an NPC (start/finish) it requires the creature_questrelation, and creature_involved relation table.

So I need to take data from one form and the input the data into appropriate tables.


So far I have:


Quote
$sql="INSERT INTO creature_template (...)
VALUES (...) ";

$result = mysql_query($sql);

if($result){
header("Location: 1a_success.php#show");
}

else {
(will link error page here)
}


I need something like

$result = mysql_query($sql1, $sql2, sql3) and then have 3 queries than run. If all 3 queries are successful then I need it to redirect to a success page.

Any ideas? Thanks!
« Last Edit: August 12, 2013, 01:33:43 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [SQL] Multiple INSERT INTO queries in one MySQL result
« Reply #1 on: August 12, 2013, 12:43:09 am »
Code: [Select]
$result_a = mysql_query ($query_a);
$result_b = mysql_query ($query_b);
$result_c = mysql_query ($query_c);
if ($result_a && $result_b && $result_c)
{
   // ...
}
else
{
   die ("one of the three queries did not succeed");
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Cuana

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 9
    • View Profile
Re: [SQL] Multiple INSERT INTO queries in one MySQL result
« Reply #2 on: August 12, 2013, 01:28:39 am »
Thank you Schlumpf, for that haste response! I never imagined it being quite so straightforward. Something so simple has been holding me back for quite a while. I must admit, I spent time on different days trying to get another piece of the site to work - and in the end it turned out I'd used a "_" somewhere I shouldn't have, and ended up being treated as a wildcard (I think).

Thanks!

/Cuana
« Last Edit: January 01, 1970, 01:00:00 am by Admin »