skip to Main Content

I am trying to use a php variable which happens to be the name of a mp3 file that is pulled from a mysql database between the Twillio tag.

My issue is when I go to the php page directly the xml seems to display correctly with the php variable however Twillio keeps saying error when it makes the call. What its suppose to do is make a call and play a mp3 file .

My code is below

<?php
 //database connection
include('../inc/dbconn.inc.php');

//lets get the actual message to say
$msgid = $_GET['msgid']; 

$msgsql = mysql_query("SELECT sms_mp3file FROM sms_messages WHERE smsid='$msgid' 
                       LIMIT 1");
$msgrow = mysql_fetch_assoc($msgsql);

$sms_mp3file = $msgrow['sms_mp3file'];

header ("content-type: text/xml"); 
?>

<Response>
   <Play>http://mobileclientreminders.com/mp3files/< ? php echo $ msgrow['sms_mp3file']; ? ></Play>
</Response>

Thanks. I had the spaces so that it would display in my post . Andre I tried putting the entire thing inside of PHP like you have in your post. However I still receive a message saying “an application error has occurred” ??

The value of $msgrow[‘sms_mp3file’]; is something like file983.mp3

I did have a space in my initial opening php tag I had < ?php instead of

3

Answers


  1. < ? php echo $ msgrow[‘sms_mp3file’]; ? >

    Those are not valid PHP open/close tags (the variable is also formatted incorrectly). Remove the extra spaces:

    <?php echo $msgrow['sms_mp3file']; ?>
    
    Login or Signup to reply.
  2. What if you do it in pure PHP without templating, using this code :

    <?php
    include('../inc/dbconn.inc.php');
    
    $msgid = $_GET['msgid']; 
    
    $msgsql = mysql_query("SELECT sms_mp3file FROM sms_messages WHERE smsid='$msgid' LIMIT 1");
    $msgrow = mysql_fetch_assoc($msgsql);
    
    $sms_mp3file = $msgrow['sms_mp3file'];
    
    header ("content-type: text/xml");
    
    echo "<Response><Play>http://mobileclientreminders.com/mp3files/".$sms_mp3file."</Play></Response>";
    

    This looks more readable and doesn’t have both HTML and PHP in the same file which makes it messy and hard to read.

    Finally, the mysql library is deprecated and should never be used, instead you should either use mysqli or PDO.

    Login or Signup to reply.
  3. You have a space inside php tag. You must write <?php instead of <? php for it to work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search