I have this code for pgsql database i am able to send the first query but i need to send both query at once they are different tables.
<?php
include_once('db/db.php');
$description = pg_escape_string($_POST['description']);
$startdate = pg_escape_string($_POST['startdate']);
$schedulestarttime = pg_escape_string($_POST['schedulestarttime']);
$scheduleendtime = pg_escape_string($_POST['scheduleendtime']);
//those 4 required for second query
$cycleid = ..; //this must be returning the cycleid of first query
$eventtypecode = 5;
$duration = 120;
$position = 6;
$query = "INSERT INTO cycles (description, startdate, schedulestarttime, scheduleendtime) VALUES('" . $description . "', '" . $startdate . "', '" . $schedulestarttime . "', '" . $scheduleendtime . "') RETURNING cycleid";
$result = pg_query($query);
if (!$result) {
$errormessage = pg_last_error();
echo "Error with query: " . $errormessage;
exit();
}
else {
$query = "INSERT INTO cycleelements (cycleid, eventtypecode, duration, position) VALUES ($cycleid, '" . $eventtypecode . "', '" . $duration . "', '" . $position . "')";
$result = pg_query($query);
if (!$result) {
$errormessage = pg_last_error();
echo "Error with query: " . $errormessage;
exit();
}
printf ("Successfully added | %s | %s | %s | %s | to the database", $cycleid, $eventtypecode, $duration, $position);
pg_close();
}
printf ("Successfully added | %s | %s | %s | %s | to the database", $description, $startdate, $schedulestarttime, $scheduleendtime);
pg_close();
?>
If someone has any tips for me what i need to change in the code so i can send both query and also there i commented that for the second query the cycleid must be returned from the first query.
Thank you, Regards