I have one file with a form, that includes another to process that form. The file with the form calls a function in the included file to write data to the database, and then I return an $insert_id from that post so I can reference it in the output.
For example, when you fill out the form on the page, the data is sent to the db from a separate file, then I want to reference the ID it was given in the original file that I called the function from.
A snippet of the file with the form that includes the db process file:
if (isset($_POST['EC_doPost']))
{
$statusPost = $_POST['EC_statusPost'];
echo "HERE: " . $this->addEvent($title, $location, $linkout, $attendees, $description, $startDate, $startTime, $endDate, $endTime, $accessLevel, $postID) . "There.";
$data = array
(
'post_content' => $output . "TESTING THIS: " . $event_id,
'post_title' => $title,
'post_date' => date('Y-m-d H:i:s'),
'post_category' => $wpdb->escape($this->blog_post_author),
'post_status' => $statusPost,
'post_author' => $wpdb->escape($this->blog_post_author),
);
}
And here is s the function (in the included file) that should return the insert_id:
function addEvent($title, $location, $linkout, $attendees, $description, $startDate, $startTime, $endDate, $endTime, $accessLevel, $postID)
{
$postID = is_null($postID) ? "NULL" : "'$postID'";
$location = is_null($location) ? "NULL" : "'$location'";
$description = is_null($description) ? "NULL" : "'$description'";
$startDate = is_null($startDate) ? "NULL" : "'$startDate'";
$endDate = is_null($endDate) ? "NULL" : "'$endDate'";
$linkout = is_null($linkout) ? "NULL" : "'$linkout'";
$attendees = is_null($attendees) ? "NULL" : "'$attendees'";
$startTime = is_null($startTime) ? "NULL" : "'$startTime'";
$accessLevel = is_null($accessLevel) ? "NULL" : "'$accessLevel'";
$endTime = is_null($endTime) ? "NULL" : "'$endTime'";
$sql = "INSERT INTO `$this->mainTable` (`id`, `eventTitle`, `eventDescription`, `eventLocation`, `eventLinkout`, `eventAttendees`,`eventStartDate`, `eventStartTime`, `eventEndDate`, `eventEndTime`, `accessLevel`, `postID`) VALUES (NULL , '$title', $description, $location, $linkout, $attendees, $startDate, $startTime, $endDate, $endTime , $accessLevel, $postID);";
$this->db->query($sql);
$landingpage = "'http://www.google.com'";
$status = "'1'";
$title = "'".$title."'";
$addedon = "'".date("Y-m-d")."'";
$sql = "INSERT INTO `$this->eventrTable` (`name`, `description`, `event_date`, `maximum_attendees`, `added_on`, `status`, `landing_page`) VALUES ($title, $description, $startDate, $attendees, $addedon, $status, $landingpage);";
$this->db->query($sql);
$event_id = $this->db->insert_id;
return $event_id;
}
What I am trying to do is make two Wordpress plugins work together, but it's not going so well just yet. If I make the included file with the function echo the variable, it works, but then I can't get it to work in the original file...
I'm sure it's something dumb, but I'm stumped.