-1

GOAL: to reveal audio player only when it's triggered by data present in the database.

The "if statement" below works, but my link, surrounded by the curly brackets ({$row['cmmnt_sng']}), is lost. This link works fine as an html audio control, minus the curly brackets and conditional. But... the control appears in every listing with or without an audio file linked to it. In the conditional, the link is lost.

Note: the curly brackets are required for code embedded in the conditional. Without them you get this little ditty: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING).

if (isset($row['cmmnt_sng'])) {
    echo "
<audio controls>
   <source src='../storedlinks_001/cmmnt_uploads/sng/<?php echo {$row['cmmnt_sng']}; ?>'>
</audio>";
        }
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Muezy
  • 1
  • 3

1 Answers1

1

your problem is the <?php echo ..?> change to this:

if (isset($row['cmmnt_sng'])) {
    echo "
<audio controls>
   <source src='../storedlinks_001/cmmnt_uploads/sng/{$row['cmmnt_sng']}'
</audio>";
        }

You're already in PHP and in the middle of an echo.

EDIT: Correction, in your case you do need the curly braces, HOWEVER, you don't need the extra '', this is valid: .../$row[cmmnt_sng]'... and in that case you wouldn't need the curlies

WheatBeak
  • 1,036
  • 6
  • 12