如何修复PHP中的“第61行上的C:\ xampp \ htdocs \ cms \ post.php中的未定义变量:Autor”错误?

时间:2019-01-31 15:20:32

标签: php xampp

我正在使用PHP和MYSQL创建CMS,但在发布页面时收到错误。我是该领域的新手,请帮助解决此问题。

这些是PHP错误:

未定义变量:第55行的C:\ xampp \ htdocs \ cms \ post.php中的zi;

未定义变量:第56行的C:\ xampp \ htdocs \ cms \ post.php中的luna;

未定义变量:第57行中的C:\ xampp \ htdocs \ cms \ post.php中的一个

未定义的变量:第60行的C:\ xampp \ htdocs \ cms \ post.php中的titlu;

未定义变量:第61行的C:\ xampp \ htdocs \ cms \ post.php中的Autor;

未定义的变量:第69行的C:\ xampp \ htdocs \ cms \ post.php中的date_postare;

未定义变量:第72行的C:\ xampp \ htdocs \ cms \ post.php中的categorii;

未定义的变量:第81行的C:\ xampp \ htdocs \ cms \ post.php中的titlu;

未定义变量:第105行的C:\ xampp \ htdocs \ cms \ post.php中的Autor;

未定义变量:第112行的C:\ xampp \ htdocs \ cms \ post.php中的post_id;

mysqli_num_rows()期望参数1为mysqli_result,在第114行的C:\ xampp \ htdocs \ cms \ post.php中给出的布尔值;

这是post.php页面的代码:

<?php require_once('inc/top.php'); ?>

  </head>
  <body>

 <?php require_once('inc/header.php'); ?>

<?php 
  if(isset($_GET['post_id'])){
      $post_id = $_GET['post_id'];

      $views_query = "UPDATE `postari` SET `vizualizari` = vizualizari + 1 WHERE `postari`.`id` = $post_id;";

      $query = "SELECT * FROM postari WHERE status = 'publicat' and id=$post_id";
      mysqli_query($conn, $views_query);

      $run = mysqli_query($conn, $query);
      if(mysqli_num_rows($run) > 0){
          $row = mysqli_fetch_array($run);
          $id = $row['id'];
          $data = getdate($row['data']);
          $zi = $data['mday'];
          $luna = $data['month'];
          $an = $data['year'];
          $titlu = $row['titlu'];
          $imagine = $row['imagine'];
          $img_autor = $row['img_autor'];
          $autor = $row['autor'];
          $categorii = $row['categorii'];
          $date_postare = $row['date_postare'];

      }
      else{
          header('Location: index.php');
      }
  }  
?>

   <div class="jumbotron">
       <div class="container">
           <div id="details" class="animated fadeInLeft">
               <h1><span>Postare</span> Personală</h1>
               <p>Despre Postare...</p>
           </div>
       </div>
       <img src="img/top_image.jpg" alt="Top Image">
   </div>
   <section>
       <div class="container">
           <div class="row">
               <div class="col-md-8">
                   <div class="post">
                        <div class="row">
                            <div class="col-md-2 post-date">
                                <div class="day"><?php echo $zi;?></div>
                                <div class="month"><?php echo $luna;?></div>
                                <div class="year"><?php echo $an;?></div>
                            </div>
                            <div class="col-md-8 post-title">
                               <a href="post.php?post_id=<?php echo $id;?>"><h2><?php echo $titlu;?></h2></a> 
                               <p>Scris de: <span><?php echo ucfirst($autor);?></span></p>
                            </div>
                            <div class="col-md-2 profile-picture">
                                <img src="img/<?php echo $img_autor;?>" alt="Imagine de Profil" class="img-circle">
                            </div>
                        </div>
                        <a href="img/<?php echo $imagine;?>"><img src="img/<?php echo $imagine;?>" alt="Imagine Postare"></a>
                        <p class="desc">
                            <?php echo $date_postare;?>
                        </p>
                        <div class="bottom">
                            <span class="first"><i class="fa fa-folder" aria-hidden="true"></i><a href="#"><?php echo ucfirst($categorii) ;?></a></span> | 
                            <span class="sec"><i class="fa fa-comment" aria-hidden="true"></i><a href="#"> Comentează</a></span>
                        </div>
                    </div>

                   <div class="related-posts">
                          <h3>Postări similare</h3><hr>
                        <div class="row">                        
                           <?php 
                            $r_query = "SELECT * FROM postari WHERE status = 'publicat' AND titlu LIKE '%$titlu%' LIMIT 3";
                            $r_run = mysqli_query($conn, $r_query);
                            while($r_row = mysqli_fetch_array($r_run)){
                                $r_id = $r_row['id'];
                                $r_titlu = $r_row['titlu'];
                                $r_imagine = $r_row['imagine'];

                            ?>
                            <div class="col-sm-4">
                                 <a href="post.php?post_id=<?php $r_id;?>">
                                    <img src="img/<?php $r_imagine;?>" alt="Slide 3">
                                    <h4><?php $r_titlu;?></h4>
                                </a>
                            </div>
                            <?php }?>
                        </div>
                    </div>

                   <div class="author">
                       <div class="row">
                           <div class="col-sm-3">
                               <img src="img/<?php $img_autor;?>" alt="Imagine Profil" class="img-circle">
                           </div>
                           <div class="col-sm-9">
                               <h4><?php ucfirst($autor);?></h4>
                               <p>Lorem Ipsum este pur şi simplu o machetă pentru text a industriei tipografice. Lorem Ipsum a fost macheta standard a industriei încă din secolul al XVI-lea, când un tipograf anonim a luat o planşetă de litere şi le-a amestecat pentru a crea o carte demonstrativă pentru literele respective. Nu doar că a supravieţuit timp de cinci secole, dar şi a facut saltul în tipografia electronică practic neschimbată. A fost popularizată în anii '60 odată cu ieşirea colilor Letraset care conţineau pasaje Lorem Ipsum, iar mai recent, prin programele de publicare pentru calculator, ca Aldus PageMaker care includeau versiuni de Lorem Ipsum.</p>
                           </div>
                       </div>
                   </div>

                   <?php 
                   $c_query = "SELECT * FROM comentarii WHERE status = 'aprobat' and postare_id = $post_id ORDER BY id DESC";
                   $c_run = mysqli_query($conn, $c_query);
                   if(mysqli_num_rows($c_run) > 0){



                   ?>

                   <div class="comment">
                      <h3>Comentarii</h3>

                      <?php
                       while($c_row = mysqli_fetch_array($c_run)){
                           $c_id = $c_row['id'];
                           $c_nume = $c_row['nume'];
                           $c_nume_utilizator = $c_row['nume_utilizator'];
                           $c_imagine = $c_row['imagine'];
                           $c_comentariu = $c_row['comentariu'];

                       ?>
                      <hr>


                        <div class="row single-comment">
                           <div class="col-sm-2">
                               <img src="img/<?php echo $c_imagine;?>" alt="Imagine Profil">
                           </div>
                           <div class="col-sm-10">
                               <h4><?php echo ucfirst($c_nume);?></h4>
                               <p><?php echo $c_comentariu;?></p>
                           </div>
                       </div>
                      <?php } ?> 
                   </div>

                   <?php }
                   if(isset($_POST['submit'])){
                       $cs_nume = $_POST['nume'];
                       $cs_email = $_POST['email'];
                       $cs_website = $_POST['website'];
                       $cs_comentariu = $_POST['comentariu'];
                       $cs_data = time();
                       if(empty($cs_nume) or empty($cs_email) or empty ($cs_comentariu)){
                           $error_msg = "Toate câmpurile (*) sunt obligatorii";
                       }
                       else{
                            $cs_query = "INSERT INTO `comentarii` (`id`, `data`, `nume`, `nume_utilizator`, `postare_id`, `email`, `website`, `imagine`, `comentariu`, `status`) VALUES (NULL, '$cs_data', '$cs_nume', 'user', '$post_id', '$cs_email', '$cs_website', 'user.png', '$cs_comentariu', 'trimitere')";
                             if(mysqli_query($conn, $cs_query)){
                                 $msg = "Comentariul a fost trimis și trebuie aprobat";
                                   $cs_nume = "";
                                   $cs_email = "";
                                   $cs_website = "";
                                   $cs_comentariu = "";
                             }
                           else{
                               $error_msg = "Eroare la trimiterea comentariului.Comentariul nu a fost trimis";
                           }
                       }
                   }
                   ?>

                   <div class="comment-box">
                       <div class="row">
                           <div class="col-xs-12">
                               <form action="" method="post">
                                   <div class="form-group">
                                       <label for="nume">Nume*:</label>
                                       <input type="text" value="<?php if(isset($cs_nume)){echo $cs_nume;}?>" id="nume" name="nume" class="form-control" placeholder="Introduceți numele și prenumele...">
                                   </div>

                                   <div class="form-group">
                                       <label for="email">Email*:</label>
                                       <input type="text" name="email" id="email" class="form-control" value="<?php if(isset($cs_email)){echo $cs_email;}?>"  placeholder="Email...">
                                   </div>

                                   <div class="form-group">
                                       <label for="website">Website:</label>
                                       <input type="text"  name="website" id="website" class="form-control" value="<?php if(isset($cs_website)){echo $cs_website;}?>"  placeholder="Adresă website...">
                                   </div>

                                   <div class="form-group">
                                       <label for="comentariu">Comentariu*:</label>
                                       <textarea id="comentariu" name="comentariu" cols="30" rows="10" placeholder="Introduceți comentariul dumneavostră aici..." class="form-control" <?php if(isset($cs_comentariu)){echo $cs_comentariu;}?> ></textarea>
                                   </div>
                                   <input type="submit" name="submit" class="btn btn-primary" value="Trimite">
                                   <?php 
                                   if(isset($error_msg)){
                                        echo "<span style= 'color:red;' class='pull-right'>$error_msg</span>";
                                   }
                                   else if(isset($msg)){
                                       echo "<span style= 'color:green;' class='pull-right'>$msg</span>";
                                   }
                                   ?>
                               </form>
                           </div>
                       </div>
                   </div>
               </div>
               <div class="col-md-4">
                   <?php require_once('inc/sidebar.php'); ?>
               </div>
           </div>
       </div>
   </section>

   <?php require_once('inc/footer.php'); ?>

0 个答案:

没有答案