Using JavaScript, PHP and MySQL to Log Captivate Variable Data
October 20, 2017
Using JavaScript, PHP and MySQL to Log Captivate Variable Data
October 20, 2017
I create very technical E-Learning Courses teaching administration fundamentals for setting up Lenel and AMAG Alarm systems.    Our training courses teach administrators at the very corporate level in companies like Kaiser and Kilroy Realty.   I also create online meditation courses. 
Newbie 3 posts
Followers: 11 people

Many Captivate developers use a Learning Management System to log E-Learning Interactions.   The variable data in a Captivate project holds very useful information about how the user is progressing in your E-Learning Course.    Definitely Learning Management Systems are great and Adobe’s Prime LMS is excellent but what if you just want to log some simple user variable data and you don’t feel the need for a full LMS.   I am going to show you how to use JavaScript and PHP to capture Captivate variable data into MySQL tables.   Once the data is posted to the MySQL tables it can be reported on using PHP or a PHP Report Generator.

This instructional video will show you how to do this:

As shown in the instructional video the JavaScript $.post command passes the Captivate variables to the PHP program.   The PHP $_REQUEST command receives the Captivate variables into the PHP program where the data is processed and stored in the MySQL table where it can be reported on.

Example JavaScript:

$.post(‘http://mindarrive.com/phpcode/startdatetime2.php’,{vemail:ls_email, vstartdatetime:v_startdatetime, vtitleno:v_titleno, vincludeintro:v_includeintro, vcompanyid:ls_companyid}, function() {});

Example PHP:

<?php

$email = $_REQUEST[“vemail”];

$startdatetime = $_REQUEST[“vstartdatetime”];

$titleno =  $_REQUEST[“vtitleno”];

$includeintro= $_REQUEST[“vincludeintro”];

$companyid= $_REQUEST[“vcompanyid”];

$conn = new mysqli($servername, $username, $password, $dbname);

$sql = “INSERT INTO userlog (email, startdatetime, titleno,includeintro, durationtime) VALUES (‘$email’, ‘$startdatetime’, ‘$titleno’, ‘$includeintro’, 10)”;

$conn->close();

?>

Hope you find this implementation useful and it helps you with your Captivate course development.

Showcase Captivate Project:

Feel free the try out these relaxing Captivate Online Meditations at:

http://mindarrive.com/zenwithlen

Enjoy!

-Steve Lewis

All Comments
Sort by:  Most Recent
Aug 30, 2021
Aug 30, 2021

Steve or anyone else,

I am pretty new to PHP and tried modeling my PHP after yours.  Here is what I came up with:

<?php
$thecapModule = $_REQUEST[“vcapModule”];
$theservername = $_REQUEST[“vservername”];
$thedbname = $_REQUEST[“vdbname”];
$theusername = $_REQUEST[“vusername”];
$thepassword = $_REQUEST[“vpassword”];
$conn = mysqli_connect($theservername, $theusername, $thepassword, $thedbname);
$sql = “INSERT INTO CaptivateData (capModule) VALUES (‘$thecapModule’)”;
$conn->query($sql);
$conn->close();
?>

The biggest difference in the code above is that it includes the PHP “query” command to process the contents of $sql.  However, I still cannot get this to work with or without that added line of code.  The following is my JavaScript (hiding the actual username, password, and domain).  In my testing, I am only trying to write the value of c_capModule to the MySQL database.

window.cpAPIInterface.setVariableValue(“c_capModule”, “Test Module”);
window.cpAPIInterface.setVariableValue(“c_servername”, “localhost”);
window.cpAPIInterface.setVariableValue(“c_dbname”, “mydbName”);
window.cpAPIInterface.setVariableValue(“c_username”, “myUsername”);
window.cpAPIInterface.setVariableValue(“c_password”, “myPassword”);

$.post(‘http://mysql.mydomain.com/private/phpcode/insertcapdata.php’,{vcapModule:c_capModule, vservername:c_servername, vusername:c_username, vpassword:c_password, vdbname:c_dbname}, function() {});

Do you spot any obvious issues?

Thanks for any guidance or tips!

Like
(1)
Aug 9, 2021
Aug 9, 2021

Thanks!

Like
()
Aug 6, 2021
Aug 6, 2021

Thanks for this useful learning

Like
()