title: Updating mysql database using While loop php
body: <p>This has been bugging me for 3 days now.. I'm new to this and trying to get my head round something. I have a form which involves 3 fields. Firstname, Surname, Marks. I have used a while loop to generate the table from a mysql table. I have used a text box and used the loop to call the text box after the 'ID' so each text box is named uniquely. I am then using a post method to send values to a second page which will update the 'marks' column with the value the user has just put in.. this is where I am finding my problem! </p>
  
  <p>This is the initial page.</p>
  
  <pre><code>&lt;html&gt; 
  &lt;head&gt;&lt;title&gt;Please Enter Your Surname&lt;/title&gt;&lt;/head&gt; 
  &lt;body&gt; 
  &lt;center&gt; 
  &lt;h2&gt;&lt;font color=blue&gt;Please Enter Your Surname&lt;/font&gt;&lt;/h2&gt;&lt;p&gt; 
  
  &lt;form action="insert.php" method="POST"&gt; 
  
  &lt;?php
  
  $db = mysql_connect("localhost","root","");
  if (!$db)
  {
      do_error("Could not connect to the server");
  }
  
  mysql_select_db("session6",$db)or do_error("Could not connect to the database");
  
  
  $result = mysql_query("SELECT * FROM members ORDER BY id",$db);
  
  
  $rows=mysql_num_rows($result);
  
  
  if(!$rows)
  {
      do_error("No results found");
  }
  else
  {
      echo "&lt;table border=3 cellspacing=1 cellpadding=1
      align=center bgcolor=lightblue&gt;\n";
      echo "&lt;caption&gt;&lt;h2&gt;&lt;font color=blue&gt; Members Details    
              &lt;/font&gt;&lt;/h2&gt;&lt;/caption&gt;\n";
      echo "&lt;tr&gt;&lt;th&gt;Member Id&lt;/th&gt;&lt;th&gt;Firstname&lt;/th&gt;&lt;th&gt;Mark&lt;/th&gt;&lt;/tr&gt;\n";
      while ($row = mysql_fetch_array($result))
      {
  
          echo "&lt;tr&gt;";
          echo "&lt;td strong&gt;" . $row['Id'] . "&lt;/td&gt;";
          echo "&lt;td strong&gt;" . $row['Firstname'] . "&lt;/td&gt;";?&gt;
          &lt;td strong&gt;&lt;input type="text" name="&lt;?php echo $row['Id']; ?&gt;" size="20"&gt;&lt;/td&gt;
          &lt;tr&gt;
          &lt;?php
  
  
  
      }
      ?&gt;&lt;input type="hidden" name="no_of_rows" value="&lt;?php echo $rows; ?&gt;"&gt;
      &lt;?php
      echo "&lt;/table&gt;\n";
  }
  
  mysql_close($db) or do_error("Could not close connection");
  
  function  do_error($error)
  {
      echo  $error;
      die();
  }
  
  ?&gt;
  &lt;input type="submit" value="Search"&gt; 
  &lt;input type="reset" value="Reset"&gt; 
  
  &lt;/form&gt; 
  
  &lt;/body&gt;&lt;/html&gt;
  `
  </code></pre>
  
  <p>Then the update is done here which is where I seem to be having a problem:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;?php
  $db = mysql_connect("localhost","root","");
  if (!$db)
  {
      do_error("Could not connect to the server");
  }
  
  mysql_select_db("marks",$db)or do_error("Could not connect to the database");
  
  $i=1;
  while ($i &lt;= $_POST["no_of_rows"])// or $_POST["No_of_Rows"] from form
  {   
  
      $insertsql = "UPDATE members SET mark = " . $_POST[$i] . " WHERE Id = " . $row['Id'] . ";"; 
      echo $_POST['$i'];
      $i++;
  
  }
  
  ?&gt;
  
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>When I echo $_POST[$i'] it shows the correct values but does not update the DB, and I'm not about ready to throw my laptop in the bin! ha! I know it is prob going to be something stupid I just can't see what, so any help would be appreciated.</p>