skip to Main Content

I have a php variable obtained from a post:

<?php
$pdf_name = $_POST['pdf_name']; 
echo $pdf_name;
?>

When I insert it into the flipbook script I get an error:

<script type="text/javascript">

      $(document).ready(function () {
          $("#read").flipBook({
            //Layout Setting
            pdfUrl:'uploads/pdf-gallery/<?php  $pdf_name ?>',
            lightBox:true,
            ...............
            ...............
            ............... etc.
        });
      })
  </script>

This is the ERROR:


pdfUrl:'uploads/pdf-gallery/<br />
<b>Warning</b>:  Undefined variable $pdf_name in <b>C:xampphtdocsmysitepdf-gallery.php</b> on line <b>81</b><br />
<br />

While if I insert this variable it works well and I get:

<?php 
$pdf_name = 'tex-willer.pdf';
echo $pdf_name;
?>


<script type="text/javascript">

      $(document).ready(function () {
          $("#read").flipBook({
            //Layout Setting
            pdfUrl:'uploads/pdf-gallery/tex-willer.pdf',
            lightBox:true,
            ........... etc
 </script>  

How can I eliminate the error from the first situation???

2

Answers


  1. Chosen as BEST ANSWER

    I inserted an alert and it works also in the first situation

    <script type="text/javascript">
    alert('<?=$pdf_name; ?>');
    </script>
    

  2. you should try this, may be this issue concatenate the value of $pdf_name with the static string ‘upload/pdf-gallery/’

    <?php
    $pdf_name = $_POST['pdf_name'];
    ?>
    
    <script>
      var pdfUrl = 'upload/pdf-gallery/' + '<?php echo $pdf_name; ?>';
      // Now you can use the 'pdfUrl' variable in your JavaScript code
      console.log(pdfUrl);
    </script>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search