Page 1 of 1

VXML and PHP

Posted: Fri Jul 06, 2007 4:24 am
by cipher#1
Hi there,

I've got a VoiceXML application that asks the caller to input his/her contact number, then VoiceXML post this number to a php script, the php script should now store this value in a mySQL database.

The code that is used in php to get the number is:

Code: Select all

$number = "";
$tmpNumber = $HTTP_POST_FILES['contact_number']['tmp_name'];
if (is_uploaded_file($tmpNumber)) {
          copy($tmpNumber, sprintf("%s",$number);
}
Could somone please help me.
Thanx.

Posted: Fri Jul 06, 2007 4:46 am
by v1ruz666
Eiervrug!!!

Posted: Fri Jul 06, 2007 5:32 am
by volka

Posted: Fri Jul 06, 2007 6:16 am
by cipher#1
Hi volka,

I did do the multiple submit and it worked (for the audio files) i just cant get numbers to work with php.

The VoiceXML submit is:

Code: Select all

<submit next="http://www.domain.com/folder/submit.php" enctype="multipart/form-data" namelist="rec_name contact_number rec_audition" method="post" maxage="0" />
and then the php script:

Code: Select all

<?php

echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
echo "<vxml version=\"2.1\" xmlns=\"http://www.w3.org/2001/vxml\" xml:lang=\"en-GB\">";
echo "<property name=\"inputmodes\" value=\"dtmf\"/>";
echo "<form>";
echo "<block>";

$msg = "";
$msg2 = "";
$code = 1;
$wavName = "";
$wavAudition = "";

$tmpName=$HTTP_POST_FILES['rec_name']['tmp_name'];

if (is_uploaded_file($tmpName)) {
	$wavName = .date("YmdHis").".wav";
	copy($tmpName, sprintf("%s", $wavName));
	$msg = "audio saved";
	echo "saved name";

} else {
	$code = 0;
	$msg = "unable to save audio";
	echo "not saved";
}

$tmpAudition=$HTTP_POST_FILES['rec_audition']['tmp_name'];

if (is_uploaded_file($tmpAudition)) {
	$wavAudition = "///###/###/###/###/###/".date("YmdHis").".wav";
	copy($tmpAudition, sprintf("%s", $wavAudition));
	$msg2 = "audio saved";
	echo "saved audition";

} else {

	$code = 0;
	$msg2 = "unable to save audio";
	echo "not saved";
}

$number = $_REQUEST["contact_number"];
 
$con = mysql_connect("########","######","######");
if (!$con) {

  die('Could not connect: ' . mysql_error());

}

mysql_select_db("###########3", $con);

$callDate = date("Ymd");
$callTime = date("His");

$sql="INSERT INTO Caller (calContactDir, calContactNum, calAuditionDir, calDate, calTime)
VALUES
('$wavName','$number','$wavAudition', '$callDate', '$callTime')";

if (!mysql_query($sql,$con)) {

  die('Error: ' . mysql_error());

}

$sql="SELECT calUniqueID FROM Caller WHERE calContactDir = '$wavName'";

$uniqueID = mysql_query($sql,$con);

mysql_close($con);

echo "</block>";
echo "</form>";
echo "</vxml>";

?>

Posted: Fri Jul 06, 2007 6:31 am
by cipher#1
Let me break it down.

The Caller calls the number, the voiceXML application picks up and asks the caller to type in a reference number form the keypad -- number?length=6 -- now the VoiceXML application sends this number to the php via a submit statement in the VoiceXML application with a POST action. Now php uses this number to check in the database if it exists and sends back a string value. I can't get the number to work with php at all, I get error messages when i get to the submit statement.

If anybody knows how to do this, please help me out, i just can't get this right.
Thank you.

Posted: Fri Jul 06, 2007 6:37 am
by volka
cipher#1 wrote:I can't get the number to work with php at all, I get error messages when i get to the submit statement.
May we see the error messages?

Posted: Fri Jul 06, 2007 6:52 am
by cipher#1
Here is the error message, it's from an AIX system.

Code: Select all

Line: 2
Column: 183
URI: null
MSG: Element type "br" must be declared

Posted: Fri Jul 06, 2007 7:00 am
by volka
Your voicexml application cannot process the html output of your php script.
I think you should install a debugger so you can trace the script's execution.
see e.g. http://www.ibm.com/developerworks/library/os-debug/