title: How to create and infinite while loop- php
body: <p>basically I have a simple user page which I access after logging in via a login page. In the user page, there is my personal data displayed from my previous registration. And there is also a form where I can enter new information such as my favourite color and hobby (which I can insert multiple times). All the records goes into the DB succesfully. The problem is, everytime I submit a new data from the form in the user page, my personal data that are displayed in the same page dissapears. When I check the DB, nothing is lost, everything remains there. The only problem is, everytime I submit a data, my personal data which is displayed on the same page dissapears. BUt when I log in, it is there again. I suspect it might be due to non-infinite while looping everytime I press the submit button to insert new information.</p>
  
  <p>How do I create an infinite while loop if this is the problem.??please help. If this is not the problem, please help me. tq so much. Below is partial of my script. tq.</p>
  
  <pre><code>    &lt;?php
  
  //useracc-test.php
  
  //start session
  session_start();
  
  
  // require 'lib/password.php';
  require 'connect-test.php';
  
  
  //retrieving part below
  
  $userName= isset($_POST['username']) ? $_POST['username'] : '';
  //$id= isset($_POST['id']);
  
  $query = "SELECT id, name, username, telno FROM users WHERE username = ?";
  $stmt = $conn-&gt;prepare($query);
  $stmt-&gt;bind_param('s', $userName);
  $stmt-&gt;execute();
  $res = $stmt-&gt;get_result(); 
  
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;style type="text/css"&gt;
  #apDiv2 {
      position: absolute;
      left: 272px;
      top: 148px;
      width: 350px;
      height: 338px;
      z-index: 1;
  }
  #apDiv3 {
      position: absolute;
      left: 37px;
      top: 379px;
      width: 320px;
      height: 157px;
      z-index: 2;
  }
  &lt;/style&gt;
  &lt;link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css"&gt;
  &lt;script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="apDiv3"&gt;
  &lt;div id="TabbedPanels1" class="TabbedPanels"&gt;
    &lt;ul class="TabbedPanelsTabGroup"&gt;
      &lt;li class="TabbedPanelsTab" tabindex="0"&gt;Tab 1&lt;/li&gt;
      &lt;li class="TabbedPanelsTab" tabindex="0"&gt;Tab 2&lt;/li&gt;
    &lt;/ul&gt;
    &lt;div class="TabbedPanelsContentGroup"&gt;
      &lt;div class="TabbedPanelsContent"&gt;
        &lt;p&gt;
  
  
        &lt;/p&gt;
        &lt;?php while($row = $res-&gt;fetch_array()): ?&gt;
        &lt;p&gt;&lt;?php echo $row['id']; ?&gt;&lt;/p&gt;
        &lt;p&gt;&lt;?php echo $row['name']; ?&gt;&lt;/p&gt;
        &lt;p&gt;&lt;?php echo $row['username']; ?&gt;&lt;/p&gt;
        &lt;p&gt;&lt;?php echo $row['telno']; ?&gt;
        &lt;?php endwhile; ?&gt;
  
  
  
  
  
  
  
  
          &lt;?php
  
  
  
   if(isset($_POST['submit']))
  
     {
      $id = $_POST['id'];
      $name2 = $_POST['name2'];
      $color2 = $_POST['color2'];
      $hobby2 = $_POST['hobby2'];
  
  
  
      $stmt = $conn-&gt;prepare("INSERT INTO useradvert (id,name2,color2,hobby2) VALUES (?,?,?,?)");
      $stmt-&gt;bind_param("isss",$id,$name2,$color2,$hobby2);
      $stmt-&gt;execute();
  
     // $stmt-&gt;close();
     // $conn-&gt;close();
     } 
  
  
      ?&gt;
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="TabbedPanelsContent"&gt;
        &lt;form name="form2" method="post" action="useracc-test.php"&gt;
          &lt;p&gt;&amp;nbsp;&lt;/p&gt;
          &lt;p&gt;id :
            &lt;input type="text" name="id" id="id"&gt;
          &lt;/p&gt;
          &lt;p&gt;name :
            &lt;input type="text" name="name2" id="name2"&gt;
          &lt;/p&gt;
          &lt;p&gt;color2 :
            &lt;input type="text" name="color2" id="color2"&gt;
          &lt;/p&gt;
          &lt;p&gt;hobby2 :
            &lt;input type="text" name="hobby2" id="hobby2"&gt;
          &lt;/p&gt;
          &lt;p&gt;
            &lt;input type="submit" name="submit" id="submit" value="submit"&gt;
          &lt;/p&gt;
        &lt;/form&gt;
        &lt;p&gt;&amp;nbsp;&lt;/p&gt;
        &lt;p&gt;&amp;nbsp;&lt;/p&gt;
        &lt;p&gt;&amp;nbsp;&lt;/p&gt;
        &lt;p&gt;&amp;nbsp;&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;    
    &lt;script type="text/javascript"&gt;
  var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    &lt;/script&gt;
  &lt;/body&gt;
                 &lt;/html&gt;
  </code></pre>