title: what's wrong with this database query?
body: <p>Here is a little piece of code in PHP.</p>
  <pre><code>&lt;?php include_once(&quot;includes/connection.php&quot;); ?&gt;
      &lt;?php include_once(&quot;includes/functions.php&quot;); ?&gt;
      &lt;?php 
          if(!isset($_POST['menu_name']) or !isset($_POST['position']) or !isset($_POST['visible'])){
              echo &quot;You are supposed to fill all entries&lt;br/&gt;&lt;br/&gt;&lt;a href='new_subject.php'&gt;go back&lt;/a&gt;&quot;;
              exit;
          }
              echo &quot;&lt;pre&gt;&quot;;
              var_dump($_POST); 
              echo &quot;&lt;/pre&gt;&quot;:
          $menu_name = $_POST['menu_name'];
          $position = (int)$_POST['position'];
          $visible = $_POST['visible'];
          $menu_name = mysql_real_escape_string($menu_name);
          $subject_count = mysql_num_rows(get_all_subjects());
          //$subject_set_desc = mysql_query(&quot;SELECT position FROM subjects ORDER by position DESC&quot;,$connection);
          for($change = $position;$change&lt;=$subject_count;$change++){
              //get row with position $change
              //increase it's position by 1
              //continue till all rows end OR loop ends
              /*UPDATE subjects SET position = $change+1 WHERE position = $change*/
              $new_position = $change+1;
              echo &quot;{$change} &quot;.gettype($change).&quot;  {$new_position} &quot;.gettype($new_position).&quot;&lt;br/&gt; &quot;;
              mysql_query(&quot;UPDATE subjects SET position = {$new_position} WHERE position = {$change}&quot;,$connection);
              echo &quot;UPDATE subjects SET position = {$new_position} WHERE position = {$change}&quot;.&quot;&lt;br/&gt;&quot;;
              //confirm_query($cheack);
              
          }
          $query = &quot;INSERT INTO subjects (menu_name,position,visible) VALUES ('{$menu_name}',{$position},{$visible})&quot;;
          if(mysql_query($query,$connection)){
              //header(&quot;location:content.php&quot;);
              exit;
          } else{
              echo &quot;&lt;b&gt;failed to insert new subject&lt;/b&gt; &lt;br/&gt;&quot;.mysql_error();
          }
      ?&gt;
      &lt;?php mysql_close($connection); ?&gt;
  </code></pre>
  <p>I want you to just focus on the <code>for</code> loop and the database query in that loop..
  I send following data via <code>post</code> to this page</p>
  <pre><code>$_POST['subject'] = 'new_subject'; //string type &lt;br/&gt;
  $_POST['position'] = 1 //int type &lt;br/&gt;
  $_POST['visible'] = 1 //tinyint type &lt;br/&gt;
  $_POST['submit'] = 'Add Subject' // string type just submisssion &lt;br/&gt;
  </code></pre>
  <p>as you can see in my form processing file</p>
  <p><img src="https://i.stack.imgur.com/etOp1.png" alt="enter image description here" /></p>
  <p>my database before making these queries</p>
  <p><img src="https://i.stack.imgur.com/6fj7m.png" alt="enter image description here" /></p>
  <p>my database after making query (in for loop of code).</p>
  <p><img src="https://i.stack.imgur.com/A4ZsA.png" alt="enter image description here" /></p>
  <p>I think position of all the rows in table should increase by 1 but all of them changed to 5..
  Here i want to increment position by 1 for those whose position is greater or equal to <code>$_POST['position']..&lt;br/&gt;</code>
  I try to echo my queries and all of them show that queries are correct but after their execution changes to table are not in way as i though(i want to increment every ones position by 1)..</p>