title: PHP fetched result code in JavaScript is not working
body: <p>I'm making a simple delete confirmation prompt with SweetAlert2, PHP and JavaScript. I'm facing a little problem in this code:</p>
  <pre><code>&lt;script&gt;
          $(document).ready(function() {
              $('.delete').click(function() {
                  Swal.fire({
                      title: 'Are you sure?',
                      text: &quot;You won't be able to revert this!&quot;,
                      icon: 'warning',
                      showConfirmButton:true,
                      showCancelButton: true,
                      confirmButtonColor: '#49a12f',
                      cancelButtonColor: '#d33',
                      confirmButtonText: 'Yes'
                  }).then((result) =&gt; {
                      if (result.isConfirmed) {
                          window.location.href = &quot;deleteuser.php?userid=&lt;?php echo $row[&quot;id&quot;]; ?&gt;&quot;;
                      }
                  })
              })
          });
      &lt;/script&gt;
  </code></pre>
  <p>with this code, when I click the button it doesn't show anything but the moment I remove this part from the code:</p>
  <pre><code>&lt;?php echo $row[&quot;id&quot;]; ?&gt;
  </code></pre>
  <p>everything works and and it redirects but the actual function doesn't work, it won't delete the data I want to delete from the database. I tried to store that PHP code in a variable somehow and use it the other way but no good, I still wasn't able to make changes. Is there any way to put PHP code in JavaScript so that it will run as I would want it to? Thanks in advance.</p>
  <p>First thing I'm doing is fetching data from database:</p>
  <pre><code>&lt;?php
  
  include_once 'connection.php';
  
  
  $sql=&quot;SELECT * FROM admin&quot;;
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute();
  
  if ($stmt-&gt;error){echo &quot;something has gone wrong&quot;;}
  $result=$stmt-&gt;get_result();
  while($row = $result-&gt;fetch_assoc()) {
  
  ?&gt;
  </code></pre>
  <p>Then here's the loop:</p>
  <pre><code>&lt;tbody class=&quot;search&quot;&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;id&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;div class=&quot;profile-img&quot;&gt;
                  &lt;img class=&quot;img-fluid&quot; src=&quot;userimg/&lt;?php echo $row[&quot;img&quot;]; ?&gt;&quot; alt=&quot;&quot;&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;firstname&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;lastname&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;email&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;phone&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;dept&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;position&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;location&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row[&quot;username&quot;]; ?&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;a class=&quot;update&quot; href=&quot;update-user.php?userid=&lt;?php echo $row[&quot;id&quot;]; ?&gt;&quot;&gt;&lt;i class=&quot;fas fa-edit&quot;&gt;&lt;/i&gt;&lt;/a&gt;
              &lt;div class=&quot;deletebut&quot;&gt;
                  &lt;a class=&quot;delete&quot;&gt;&lt;i class=&quot;fas fa-trash&quot;&gt;&lt;/i&gt;&lt;/a&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  <p>Under <strong>&lt;/ tbody&gt;</strong> I close the loop:</p>
  <pre><code>&lt;?php
  }
   $conn-&gt;close();
  ?&gt;
  </code></pre>
  <p>And at the end of the code I use this JavaScript:</p>
  <pre><code>    &lt;script&gt;
          $(document).ready(function() {
              $('.delete').click(function() {
                  Swal.fire({
                      title: 'Are you sure?',
                      text: &quot;You won't be able to revert this!&quot;,
                      icon: 'warning',
                      showConfirmButton:true,
                      showCancelButton: true,
                      confirmButtonColor: '#49a12f',
                      cancelButtonColor: '#d33',
                      confirmButtonText: 'Yes'
                  }).then((result) =&gt; {
                      if (result.isConfirmed) {
                          window.location.href = &quot;deleteuser.php?userid=&lt;?php echo $row[&quot;id&quot;]; ?&gt;&quot;;
                      }
                  })
              })
          });
      &lt;/script&gt;
  </code></pre>