返回包含PHP的HTML表时出现PHP语法错误

w8rqjzmb  于 2023-04-28  发布在  PHP
关注(0)|答案(2)|浏览(105)

这是我想用来回显HTML表的代码,其中包含som PHP。编辑:对不起,我认为问题是我没有给你看完整的代码。也许这会改变一些事情。

<!doctype html> 
<html> 
  <head>
     <title>Search</title>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
     <link rel="stylesheet" href="styles.css">  
  </head>
  <body>

<?php
include("config.php");
if (isset($_POST['input'])){

    $input = $_POST['input'];
    $query = "SELECT * FROM videos WHERE location LIKE '{$input}%' 
  OR FileName LIKE '{$input}%' OR ImageSize LIKE '{$input}%' OR MediaDuration LIKE '{$input}%' 
  OR VideoFrameRate LIKE '{$input}%' OR CreateDate LIKE '{$input}%' OR author LIKE '{$input}%' OR tags LIKE '{$input}%' OR genre LIKE '{$input}%' OR rating LIKE '{$input}%'";
    $result = mysqli_query($con,$query);

    $fetchVideos = mysqli_query($con, "SELECT * FROM videos WHERE location LIKE '{$input}%' OR FileName LIKE '{$input}%' OR ImageSize LIKE '{$input}%' OR MediaDuration LIKE '{$input}%' 
  OR VideoFrameRate LIKE '{$input}%' OR CreateDate LIKE '{$input}%' OR author LIKE '{$input}%' OR tags LIKE '{$input}%' OR genre LIKE '{$input}%' OR rating LIKE '{$input}%'");
     while($row = mysqli_fetch_assoc($fetchVideos)){
       
       
      echo '<?php
      $select="select * from videos";
      $result=mysqli_query($con,$select);
  ?>
  <table class="table table-bordered" style="margin-top: 50px;">
      <tr>
          <th> Video </th>
          <th> Názov </th>
          <th> Autor </th>
          <th> Tagy </th>
          <th> Žáner </th>
          <th> Hodnotenie </th>
          <th> Rozlíšenie videa </th>
          <th> Počet Snímkov </th>
          <th> Dĺžka videa</th>s
          <th> Dátum Vytvorenia </th>
      </tr>
      <?php foreach($result as $rows) { ?>
          <tr>
              <td><video src="<?php echo $location; ?>" controls width='320px' height='320px' ></video></td>
              <td><?php echo $rows['FileName']; ?></td>
              <td><?php echo $rows['author']; ?></td>
              <td><?php echo $rows['tags']; ?></td>
              <td><?php echo $rows['genre']; ?></td>
              <td><?php echo $rows['rating']; ?></td>
              <td><?php echo $rows['ImageSize']; ?></td>
              <td><?php echo $rows['VideoFrameRate']; ?></td>
              <td><?php echo $rows['MediaDuration']; ?></td>
              <td><?php echo $rows['CreateDate']; ?></td>
          </tr>
      <?php } ?>
  </table>';

       </body>
</html>

我有麻烦的一部分,我试图使用PHP的回声功能。我不知道问题出在哪里。

<tr>
             <td><video src='".$location."' controls width='320px' height='320px' ></video></td>  
             <td><?php echo $rows['FileName']; ?></td>
             <td><?php echo $rows['author']; ?></td>
             <td><?php echo $rows['tags']; ?></td>
             <td><?php echo $rows['genre']; ?></td>
             <td><?php echo $rows['rating']; ?></td>
           <td><?php echo $rows['ImageSize']; ?></td> 
           <td><?php echo $rows['VideoFrameRate']; ?></td> 
             <td><?php echo $rows['MediaDuration']; ?></td>
           <td><?php echo $rows['CreateDate']; ?></td> 
           </tr>
vjrehmav

vjrehmav1#

这应该可以工作:

<?php
    $select="select * from videos";
    $result=mysqli_query($con,$select);
?>
<table class="table table-bordered" style="margin-top: 50px;">
    <tr>
        <th> Video </th>
        <th> Názov </th>
        <th> Autor </th>
        <th> Tagy </th>
        <th> Žáner </th>
        <th> Hodnotenie </th>
        <th> Rozlíšenie videa </th>
        <th> Počet Snímkov </th>
        <th> Dĺžka videa</th>
        <th> Dátum Vytvorenia </th>
    </tr>
    <?php foreach($result as $rows) { ?>
        <tr>
            <td><video src="<?php echo $location; ?>" controls width='320px' height='320px' ></video></td>
            <td><?php echo $rows['FileName']; ?></td>
            <td><?php echo $rows['author']; ?></td>
            <td><?php echo $rows['tags']; ?></td>
            <td><?php echo $rows['genre']; ?></td>
            <td><?php echo $rows['rating']; ?></td>
            <td><?php echo $rows['ImageSize']; ?></td>
            <td><?php echo $rows['VideoFrameRate']; ?></td>
            <td><?php echo $rows['MediaDuration']; ?></td>
            <td><?php echo $rows['CreateDate']; ?></td>
        </tr>
    <?php } ?>
</table>

但我建议你学习如何混合html和php。首先尝试只使用php输出数据(所有在单个<?php … ?>中),而不使用任何html。然后在下一步中,你可以尝试混合HTML。慢慢走,一步一步来。这样,当你犯了语法错误时,你会注意到。
编辑:
试试这个:

<!doctype html>
<html>
  <head>
     <title>Search</title>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
     <link rel="stylesheet" href="styles.css">
  </head>
  <body>

<?php
include("config.php");
if (isset($_POST['input'])) {

    $input = $_POST['input'];
        $select="SELECT * from VIDEOS";
        $result=mysqli_query($con,$select);

?>
        <table class="table table-bordered" style="margin-top: 50px;">
                <tr>
                        <th> Video </th>
                        <th> Názov </th>
                        <th> Autor </th>
                        <th> Tagy </th>
                        <th> Žáner </th>
                        <th> Hodnotenie </th>
                        <th> Rozlíšenie videa </th>
                        <th> Počet Snímkov </th>
                        <th> Dĺžka videa</th>s
                        <th> Dátum Vytvorenia </th>
                </tr>
                <?php while($row = $result->mysqli_fetch_assoc()) { ?>
                <tr>
                        <td><video src="<?php echo $location; ?>" controls width="320px" height="320px" ></video></td>
                        <td><?php echo $row['FileName']; ?></td>
                        <td><?php echo $row['author']; ?></td>
                        <td><?php echo $row['tags']; ?></td>
                        <td><?php echo $row['genre']; ?></td>
                        <td><?php echo $row['rating']; ?></td>
                        <td><?php echo $row['ImageSize']; ?></td>
                        <td><?php echo $row['VideoFrameRate']; ?></td>
                        <td><?php echo $row['MediaDuration']; ?></td>
                        <td><?php echo $row['CreateDate']; ?></td>
                </tr>
                <?php } // end of while loop ?>
        </table>';

    <?php } // end of if-clause ?>

    </body>
</html>

你还应该在SQL-Queries中使用预处理语句,否则你的程序很容易受到sql注入的攻击。

xfb7svmp

xfb7svmp2#

这是因为你将$作为注解而不是变量回显。你应该使用 backtick)。echo $ >your codes here< $;`

echo `<table class="table table-bordered" style="margin-top: 50px;"> 
   <tr> 
   <?php 
   $select="select * from videos"; 
   $result=mysqli_query($con,$select); 
   ?>
   <!--<th colspan="4"><h2>Student Record</h2></th> -->
   </tr> 
         <th> Video </th>
      <th> Názov </th>
         <th> Autor </th>
         <th> Tagy </th>
         <th> Žáner </th>
         <th> Hodnotenie </th>
      <th> Rozlíšenie videa </th> 
      <th> Počet Snímkov </th> 
         <th> Dĺžka videa</th>
      <th> Dátum Vytvorenia </th> 
   </tr> 
   <tr>
   <td><video src='".$location."' controls width='320px' height='320px' ></video></td>  
   <td><?php echo $rows['FileName']; ?></td>
   <td><?php echo $rows['author']; ?></td>
   <td><?php echo $rows['tags']; ?></td>
   <td><?php echo $rows['genre']; ?></td>
   <td><?php echo $rows['rating']; ?></td>
   <td><?php echo $rows['ImageSize']; ?></td> 
   <td><?php echo $rows['VideoFrameRate']; ?></td> 
   <td><?php echo $rows['MediaDuration']; ?></td>
   <td><?php echo $rows['CreateDate']; ?></td> 
   </tr> 
   <?php 
         } 
   ?> 
</table> `;

相关问题