October 20, 2017
Using JavaScript, PHP and MySQL to Log Captivate Variable Data
Comments
(10)
October 20, 2017
Using JavaScript, PHP and MySQL to Log Captivate Variable Data
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
(10)

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

10 Comments
2021-08-30 22:30:25
2021-08-30 22:30:25

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)
2021-08-09 16:35:44
2021-08-09 16:35:44

Thanks!

Like
2021-08-06 20:04:33
2021-08-06 20:04:33

Thanks for this useful learning

Like
2021-08-06 20:03:46
2021-08-06 20:03:46

Thanks! It’s very helpful!

Like
2018-05-13 17:23:18
2018-05-13 17:23:18

hi, mr lewis, i need your help with something…

we are created a simulator for ms word, and we need save data with php and mysql, so we need to know if you can help us with this…

thanks,

jpolonia.

Like
2018-02-26 20:33:22
2018-02-26 20:33:22

Tried this code using a MSSQL connection but can’t seem to get it working…I am trying to send a variable from a textbox (tried to get the userid via system but it comes blank every time) and the user final score to an MSSQL server…

Like
2017-10-24 17:06:25
2017-10-24 17:06:25

In the session now! Great learning!

Like
2017-10-21 15:23:07
2017-10-21 15:23:07

Your sample project looks good on my Samsung S7.

Like
(1)
>
Paul Wilson
's comment
2017-10-21 16:53:53
2017-10-21 16:53:53
>
Paul Wilson
's comment

Thanks Paul, you taught me well. After your class I’ll really understand Fluid Boxes and the project will look even better!

Like
2017-10-21 04:37:38
2017-10-21 04:37:38

Excellent post Steve. Looking forward to seeing you in Vegas.

Like
Add Comment