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

Passing Data to for SQL Query

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
echologic
Posts: 2
Joined: Fri Aug 12, 2016 10:42 am

Passing Data to for SQL Query

Post by echologic »

Hi,

I'm having trouble passing an vxml variable into my database using php.

I'm trying to run a query against the database table element: ID.

I'm using the root document method to pass the variable between pages and can confirm the variable is present on the desired page, but I cannot get the variable to pass thru to run a query.

My first page is: root.php

Code: Select all

<?php
header("Content-type: text/xml");
echo("<?xml version=\"1.0\"?>\n");
?>

<vxml version="2.0">
<var name="lookUp"/>
<form id="mainmenu">
  <field name="menuchoice">
    <grammar type="application/x-jsgf" mode="dtmf">
      1|0|5
    </grammar>
      <prompt>
        Press 1 to begin the voting process.
        Press 0 to hear this message again.
        press 5 to hear the telephone number again.
      </prompt>
      <filled>
        <if cond="menuchoice==1">
          <goto next="page1.php"/>
        <elseif cond="menuchoice==0"/>
          <goto next="root.php"/>  
        <elseif cond="menuchoice==5"/>
          617-712-3999 x8723
        </if>
      </filled>
  </field>
</form>
</vxml>
Here is my second page which takes input from plum and places it in a variable <assign name="lookUp" expr="lookUp"/>:

Code: Select all

<?php
  header("Content-type: text/xml");
  echo "<?xml version=\"1.0\"?>\n";	
?>

<vxml version="2.0" application="root.php">
  <form>
    <field name="lookUp" type="digits?length=5">
      <prompt>
        Please enter your identification number.
      </prompt>
      <filled>
        <assign name="lookUp" expr="lookUp"/>
        <submit next="page2.php" method="post" namelist="lookUp" fetchtimeout="60s"/>
      </filled>
      <noinput>
        <prompt>
          Sorry, I didn't hear you.
        </prompt>
        <reprompt/>
      </noinput>
      <nomatch>
        <prompt>
          Sorry, I didn't understand you.
        </prompt>
        <reprompt/>
      </nomatch>
    </field>
  </form>
</vxml>
Here's the third page in which I'm trying to pass the variable to php for a query against the DB.

Code: Select all

<?php
header("Content-type: text/xml");
echo("<?xml version=\"1.0\"?>\n");
$dbhost='provider';
$dbusername='username';
$dbuserpass='password';
$dbname='dbname';
$dbTable='dbtable';

$myXMLData =
"<?xml version='1.0' encoding='UTF-8'?>
<'lookUp'>";

$sxml = simplexml_load_string($myXMLData);
//print_r($sxml);

$conn = mysql_connect($dbhost, $dbusername, $dbuserpass) or die('Error connecting to mysql'.mysql_error());
mysql_select_db($dbname);

$result = mysql_query("SELECT * FROM dbTable WHERE ID ='$sxml'") or die(mysql_error());
$program_name=mysql_fetch_assoc($result);
mysql_close($conn);
?>

<vxml version="2.0" application="root.php">
  <form>
    <field name="lookUp" type="digits">
      <filled>
        Your identification number is: <value expr="lookUp"/>
      </filled>
    </field>
<var name="program_name" expr="'<?echo($program_name["STATUS"] . ", " . $program_name["FIRSTNAME"]. " " . $program_name["LASTNAME"])?>'" />
<block>
<prompt>This is <value expr="program_name"/>
</prompt>
</block>  
</form>
</vxml>
Any insight would be greatly appreciated.

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

Re: Passing Data to for SQL Query

Post by support »

Hello,

Because your <submit> tag is using a "post" to return the data, you will want to get your VXML variable "lookUp" as follows in your PHP script:

Code: Select all

$lookUp = $_POST['lookUp'];
then pass it into your database query as follows:

Code: Select all

$result = mysql_query("SELECT * FROM dbTable WHERE ID ='$lookUp'") or die(mysql_error());
Regards,
Plum Support

echologic
Posts: 2
Joined: Fri Aug 12, 2016 10:42 am

Re: Passing Data to for SQL Query

Post by echologic »

Thank you...that helped :D

Post Reply