1

I am doing a dynamic site. My main page shows a persons profile on the left and the articles written by him on the right.This is my main page.When i click 'read more', that particular article should open up in a new page on the left, and the remaining articles written by the same person should be shown on the right. But here all the articles are shown This is the image of my blog page. I only want the selected article to be shown on the left and all the remaining articles on the right.

This is my table for articles. In the first page i am calling the articles on the right using the person's id. This is the code for my first page:

 <div class="container">
 <?php
 session_start();
 $q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);

$sql="select * from person_details where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
 
 
?>
<div>
  <div class="row">
   <div style="background-color:rgba(125, 178, 194, 0.43); margin-bottom:10px;" class="col-sm-8 col-md-8 col-lg-8">
    <div class="row">
     <div class="col-sm-4 col-md-4 col-lg-4">
      <img style="margin:20px;" src="uploads/<?php echo $ar[17]; ?>">
     </div>
     <div class="col-sm-8 col-md-8 col-lg-8">
      <h3><b>Mr. <?php echo $ar[1];?></b></h3>
      <h5><?php echo $ar[8];?>, <?php echo $ar[12];?></h5>
      <h5><?php echo $ar[2];?>, <?php echo $ar[7];?> years of experience</h5>
      <p><?php echo $ar[16];?></p>
    </div>
    </div>
       <div style="margin:20px;">
        <h4><b>Services</b></h4>
        <hr>
        <ul>
         <li>
         <h5><?php echo $ar[18]; ?></h5>
         </li>
        </ul>
        <h4><b>Specialisations</b></h4>
        <hr>
         <ul>
          <li>
           <h5><?php echo $ar[2]; ?></h5>
           </li>
         </ul>
        <h4><b>Education</b></h4>
        <hr>
         <ul>
           <li>
           <h5><?php echo $ar[8]; ?> - <?php echo $ar[9]; ?> , <?php echo $ar[10]; ?> , <?php echo $ar[11];?></h5>
          </li>
         </ul>
          <ul>
         <li>
          <h5><?php echo $ar[12]; ?> - <?php echo $ar[13]; ?> , <?php echo $ar[14]; ?> , <?php echo $ar[15];?></h5>
        </li>
        </ul>
        
        </div>
        
   </div>
    
  <div class="col-sm-4 col-md-4 col-lg-4">
  <h3>Articles by Mr. <?php echo $ar[1];?></h3><?php } ?>
  <hr>
  <?php
  $sql1="select * from article_tb where id=$q";
$res1=mysql_query($sql1);
while($ar=mysql_fetch_array($res1))
{
 $_SESSION['id'] = $q;
 ?>
  <h4><b><?php echo $ar[1]; ?></b></h4>
   <div class="row">
    <div class="col-sm-6 col-lg-6 col-md-6">
     <img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88">
    </div>
    <div class="col-sm-6 col-md-6 col-lg-6">
      <?php echo $ar[5]; ?>
    &nbsp; <form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read more" />
</form>
    </div>
   </div>
      <hr>
 
 
  
 
  
<?php } ?></div>
</div>

  </div>
and this is the code for my second page:

 <div class="container">
 <?php
 session_start();
 
 $q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);
$sql="select * from article_tb where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
?>
<div>
  <div class="row">
   <div style="border:1px solid #005212;"  class="col-sm-8 col-md-8 col-lg-8">
    <div class="row">
     <center><img style="margin-top:10px;" src="uploads/<?php echo $ar[3]; ?>" /></center>
            <div  class="col-sm-12 col-md-12 col-lg-12">
          <h4><b><?php echo $ar[1]; ?></b></h4>
          <p><?php echo $ar[2]; ?></p>
          </div>
        </div>
      
   </div>
    
  <div class="col-sm-4 col-md-4 col-lg-4">
  
  
  <h4><b><?php echo $ar[1]; ?></b></h4>
   <div class="row">
    <div class="col-sm-6 col-lg-6 col-md-6">
     <img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88" />
    </div>
    <div class="col-sm-6 col-md-6 col-lg-6">
        <?php echo $ar[5]; ?>
     &nbsp; <form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read more" />
</form>
    </div>
   </div>
      <hr>
  
  </div></div></div>
  
<?php } ?>
Can somebody please help me?
Helen
  • 43
  • 8
  • For the second page you're retrieving the posts based on the row 'id', which is the same for all articles. You probably want to filter by the row 'aid' instead of 'id'. – Stefan R May 19 '18 at 09:37
  • Even data from a session that you are using in a query needs to be protected against SQL injections.. https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1.. Very important if you are on shared webhosting where the hoster might have configured all apache virtual hosts to use the same session path directory.. Then you are open to a attack called `Session poisoning` through session modification http://seclists.org/bugtraq/2005/Sep/193.. Also defining your own `session_save_path()` or `a custom session handler` would be recommended because of that. – Raymond Nijland May 19 '18 at 10:49

0 Answers0