title: $_GET or $_SESSION for passing variable
body: <p>Hello monsters of programming. I just want to ask a question about using <code>$_SESSION</code> and <code>$_GET</code>. When to use <code>$_GET</code> and <code>$_SESSION</code>? what is the best for passing variable? Im just new to php and html and i don't know what is the best practice. Can someone help me to understand both of them?</p>
  
  <p>Here is the example of my code. I used <code>$_SESSION</code> for passing the variable <code>$newsid;</code></p>
  
  <p>here is the edit.php</p>
  
  <pre><code>  &lt;?php
            session_start();
             include_once('connection.php');
             $sql ="SELECT * FROM news ORDER BY news_id";
             $result = mysqli_query($con, $sql);
  
             while($row = mysqli_fetch_array($result)){
                     $newsid = $row['news_id'];
                      $title = $row['news_title'];
                       $date = $row['news_date'];
                       $content = $row['news_content'];
                       $newsimage = $row['news_image'];
  
                       ?&gt;
                       &lt;div class="fix single_news"&gt;
                         &lt;div class="single_image"&gt;
                             &lt;img src="&lt;?php echo $newsimage; ?&gt;" style="width:200px; height:140px; alt="court"&gt;
                         &lt;/div&gt;
                         &lt;a href="#"&gt;&lt;?php echo $title; ?&gt;&lt;/a&gt;
                         &lt;p&gt;&lt;?php echo $date; ?&gt;&lt;/p&gt;
                       &lt;p&gt;&lt;?php echo $content; ?&gt;&lt;/p&gt;
                       &lt;/div&gt;
                       &lt;form  action="" method="post"&gt;
                         &lt;input type='hidden' name="news_id" value="&lt;?php echo $newsid;?&gt;"&gt;
                       &lt;input type="submit" name="esubmit" value="edit" /&gt;
                       &lt;/form&gt;
                        &lt;hr&gt;
                      &lt;?php
                       }
                     if(isset($_POST['esubmit'])){
                       $_SESSION['news_id'] = $_POST['news_id'];
                        header('Location: edit2.php');
                        }
                       ?&gt; 
  </code></pre>
  
  <p>here is the edit2.php</p>
  
  <pre><code>&lt;?php
  session_start();
  
  $id = $_SESSION['news_id'];
  include_once('connection.php');
  $sql = "SELECT * FROM news WHERE news_id = '$id'";
  $result = mysqli_query($con,$sql);
  
  
                           while($row = mysqli_fetch_array($result)){
                           $title = $row['news_title'];
                           $date = $row['news_date'];
                           $content = $row['news_content'];
                           $newsimage = $row['news_image'];
                           }
  
                           ?&gt;   
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  
      &lt;form method="post" action ="" enctype="multipart/form-data"&gt;
      Title&lt;input type ="text" name ="title" value="&lt;?php echo $title;?&gt;"/&gt;&lt;br&gt;
          Date&lt;input type ="text" name="date" value="&lt;?php echo $date;?&gt;" /&gt;&lt;br&gt;
          Content&lt;textarea name="content"&gt;&lt;?php echo $content;?&gt;&lt;/textarea&gt;
          &lt;input type="submit" name="submit" value="Update" /&gt;
          &lt;input class="form-control" id="image" name="image" type="file" accept="image/*" onchange='AlertFilesize();'/&gt;
          &lt;img id="blah" src="&lt;?php echo $newsimage;?&gt;" alt="your image" style="width:200px; height:140px;"/&gt;
  
      &lt;/form&gt;
      &lt;hr&gt;
  
  
  &lt;script src="js/jquery-1.12.4.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>