We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

Submitting VXML data into MySQL db

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Submitting VXML data into MySQL db

Post by Chris »

Collecting an end user's phone number is successful.
However, when the following submit is executed -- <submit method="post" namelist="p_phone" next="AddToDB/enter_data.php"/>
I get a "bad.fetch" announcement when calling on the phone.
And the error log shows 2 errors [error no_ani 7 [23/Jul/2008:14:29:38 -0400] 5734 000000;007;1216837223 DocumentParser::FetchDocument - Parse error in file "AddToDB/enter_data.php", line 1, column 1 - Invalid document structure]
[error no_ani 7 [23/Jul/2008:14:29:38 -0400] 5734 000000;007;1216837223 errno: 205 uri AddToDB/enter_VXML_data.php]

What does that tell you?
Invalid document structure?
But the same php document (enter_data.php) is used in another application where it is called on by a PHP document not a VXML document -- and it does indeed work properly -- inserting data everytime into the MySQL db. Without fail.

So, unless I'm wrong, the (enter_data.php) code must be written differently when submitting from VXML than it is when submitting from a PHP document.

If that is the case, what should the code be in the (enter_data.php) document?

enter_data.php

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name) 
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
?>
I've also tried the following code, renaming the file to
(enter_VXML_data.php) and reworking the VXML submit to the following:
(<submit method="post" namelist="p_phone" next=AddToDB/enter_VXML_data.php"/>
Again the phone gives me a Bad.Fetch error and the error log presents:
[error no_ani 26 [23/Jul/2008:13:38:11 -0400] 5734 000001;026;1216833916 DocumentParser::FetchDocument - Parse error in file "AddToDB/enter_VXML_data.php", line 1, column 4 - Unknown element 'br']
[error no_ani 26 [23/Jul/2008:13:38:11 -0400] 5734 000001;026;1216833916 errno: 205 uri AddToDB/enter_VXML_data.php]

Wait! Line 1 is just <?PHP, there is no column 4, or any column for that matter, and there is no 'br' in the entire (enter_VXML_data.php) document.

enter_VXML_data.php

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$query="INSERT INTO web_enrollment (p_phone) VALUES (namelist="p_phone")";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
?>
Oh just in case you are wondering the columns in the MySQL db are p_phone, ,p_email,p_sex,p_first_name,p_last_name.

I hope you can show me a solution because although the Plum Tutorial demonstrates how to insert a voice recording into a document for saving it does not address these issues.
Thank you,
Thanks,
Chris

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

IVR developer explains <submit> tag

Post by support »

Hi Chris,

The reason why you are getting these IVR errors is because your php files don't have any return VXML in them. Please keep the following in mind:
The <submit> tag performs a GET or POST that will trigger a page transition. This means that document level variables will be lost once the new page is fetched and parsed. To preserve some of the current execution context, the <submit> tag can send document level variables as POST or GET variables to your application server script. This application server script gets parsed by your application server, which can then process variables sent to it before generating a VoiceXML document to be parsed by the VoiceXML platform to interact with the caller.
Also, when you are going through your IVR call logs, you should click on your last VXML file in the IVR call log ("Click here to view saved VoiceXML script") to see what's actually being returned by your web browser in order to debug these IVR issues.

Hope this helps.

Regards,
Plum Support
Last edited by support on Thu Feb 18, 2010 4:08 pm, edited 2 times in total.

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Post by Chris »

No your response did not help at all.
I was hoping you could tell me which of the two scripts was the one to fix and exactly how to fix it.
I tried to follow your advice and at the end of the document I added the following:
<?xml version="1.0"?>
<vxml version="2.0" application="e01_Enrollment.vxml">
<goto next="e06_P_Phone.vxml"/>
</vxml>
But I still get the same errors. And when I go to the call logs as you suggested there is no clickable link to my last VXML file. ("Click here to view saved VoiceXML script") does not exist.

So if it's not too much trouble, please provide the correct code to solve this problem.
Thanks,
Thanks,
Chris

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Use call log to view saved IVR script

Post by support »

Hi,

For your additional IVR code:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0" application="e01_Enrollment.vxml">
<goto next="e06_P_Phone.vxml"/>
</vxml> 
you cannot put a <goto> tag in between <vxml>tags as <goto> is not a child tag of <vxml>. The <goto> tag can only be placed in between the following IVR tags:

<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>

As for viewing your IVR call log, you can only view your vxml script on the most recent call log since older IVR call logs don't have saved VoiceXML. In order to view it, you need to look at the "Last Call Log" at the top of the list for your phone number. So, you would have to call in again and then go look at your IVR call log to view the saved VoiceXML script.

Regards,
Plum Support
Last edited by support on Thu Feb 18, 2010 4:09 pm, edited 5 times in total.

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Errors every which way

Post by Chris »

After following your instructions and making several attempts at different variations I continue to get errors. The first one gives me a "syntax error, unexpected T_STRING in ... on line 22"

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name)
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
?>
<?xml version="1.0"?>
<vxml version="2.0" application="e01_Enrollment.vxml">
<block>
<goto next="../INBOUND/e06_P_Phone.vxml"/> 
</block>
</vxml>
So I removed the "quotes" and replaced them with '
The result is another "syntax error, unexpected T_STRING in ...on line 22"

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

// select the specific database name we want to access.

if (!mysql_select_db($dbname)) die(mysql_error());


$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name) 
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());

?>
<?xml version='1.0'?>
<vxml version='2.0' application='e01_Enrollment.vxml'>
<block>
<goto next='../INBOUND/e06_PatientPhone.vxml'/> 
</block>
</vxml>
And the following variation gives me syntax error, unexpected '<' .... on line 22 when "?>" is moved to the end of the document.

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

// select the specific database name we want to access.

if (!mysql_select_db($dbname)) die(mysql_error());


$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name) 
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());


<?xml version="1.0"?>
<vxml version="2.0" application="e01_Enrollment.vxml">
<block>
<goto next="../INBOUND/e06_PatientPhone.vxml"/> 
</block>
</vxml>
?>
The variation below returns a " syntax error, unexpected '<' in ... on line 22"

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

// select the specific database name we want to access.

if (!mysql_select_db($dbname)) die(mysql_error());


$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name) 
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());


<?xml version='1.0'?>
<vxml version='2.0' application='e01_Enrollment.vxml'>
<block>
<goto next='../INBOUND/e06_PatientPhone.vxml'/> 
</block>
</vxml>
?>
Now, I'm hoping that you have a variation of the code that actually works. I would appreciate it.
Thank you,
Thanks,
Chris

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

IVR developer makes subtle changes to user's code

Post by support »

Hi,

Your first block of IVR code was pretty close:

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name)
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
?>
<?xml version="1.0"?>
<vxml version="2.0" application="e01_Enrollment.vxml">
<block>
<goto next="../INBOUND/e06_P_Phone.vxml"/>
</block>
</vxml> 
However, you need to put

Code: Select all

<?xml version="1.0"?>
inside of an echo in your php

Code: Select all

echo("<?xml version=\"1.0\"?>\n");
since <? is a reserved set of characters in php and the parser will interpret any text that follows as php, not as a string.

Secondly, for your VoiceXML, your IVR <block> tag needs to be placed within IVR <form> tags since <vxml> is not a parent tag of the <block> tag.

So, your IVR code should be edited to this:

Code: Select all

<?php 
$dbhost='HHHHHHHHHHHHHH'; 
$dbusername='UUUUUU'; 
$dbuserpass='PPPPPPPPPPP'; 
$dbname='NNNNNNNN'; 

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass); 

if (!mysql_select_db($dbname)) die(mysql_error()); 

$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name) 
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')"; 
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error()); 
echo("<?xml version=\"1.0\"?>\n");
?> 
<vxml version="2.0" application="e01_Enrollment.vxml"> 
<block> 
<goto next="../INBOUND/e06_P_Phone.vxml"/>  
</block> 
</vxml> 
Regards,
Plum Support
Last edited by support on Thu Feb 18, 2010 4:10 pm, edited 3 times in total.

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Thank you

Post by Chris »

Okay, that works. Thank you very very much!
Now I'm challenged with getting the VXML to recite the data that's in the MySQL db.
Wish me luck. I'll need it.
Thanks again.
Thanks,
Chris

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Post by Chris »

Everything was fine with this file until last night.
It just stopped and it's giving me a bad.fetch at this point \n"); ?>

How can that be? One minute it's okay the next it's not!
Also, I've noticed (when it was working) that it started putting p_first_name into p_last_name in the db! That doesn't make sense either. Any ideas on that?

Code: Select all

<?php
$dbhost='HHHHHHHHHHHHHH';
$dbusername='UUUUUU';
$dbuserpass='PPPPPPPPPPP';
$dbname='NNNNNNNN';

$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$query="INSERT INTO web_enrollment (p_phone,p_email,p_sex,p_first_name,p_last_name)
VALUES ('$_POST[p_phone]','$_POST[p_email]','$_POST[p_sex]','$_POST[p_first_name]','$_POST[p_last_name]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error()); 
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());

echo(<?xml version=\"1.0\"?>\n");
?>
<vxml version="2.0">
<form id="enter_VXML_data">
<block>
<goto next="../e01_Enrollment.vxml"/> 
</block>
</form>
</vxml>
Thanks,
Chris

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Use call log to help debug IVR issue

Post by support »

Hi Chris,

Have you tried looking at the last VXML file in your IVR call log? This would help you in debugging your IVR issue.

Regards,
Plum Support
Last edited by support on Thu Feb 18, 2010 4:11 pm, edited 2 times in total.

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Post by Chris »

Yes I have and I don't understand the error message Re: enter_VXML_data.php

XML Parsing Error: syntax error
Location: http://us.popproxy.plumgroup.com/lastvx ... 34__2.vxml
Line Number 1, Column 1:

Column count doesn't match value count at row 1
^


Keep in mind that the file was working yesterday.
How can it just fizz out?
Thanks,
Chris

Chris
Posts: 64
Joined: Wed Jul 23, 2008 12:50 pm

Fixed

Post by Chris »

Okay, I'm able to fix the "enter_VXML_data.php" but don't see where the problem was.
Thanks,
Chris

Post Reply