title: How to get last inserted row value in PHP and add 1 to it
body: <p>I'm working on an iOS app to give users more options when they purchase a license. I'm mostly familiar with ObjC and xCode so I don't know much PHP. </p>
  
  <p>Here is the setup of the MySql table:</p>
  
  <p><img src="https://i.stack.imgur.com/qevs3.png" alt="MySql table"></p>
  
  <p>I'm trying to get the rw_app_id from the last entry in the table &amp; +1 to it. Then enter it into a new row of the database. Below is the code I have constructed so far. Much help appreciated, I've entered over 2,500 entrees to this database manually and I'm so tired of doing it. Please help me keep my sanity. An explanation of code given would be great. Thanks.</p>
  
  <pre><code>$increase = stripslashes($_GET['increase']);
  $email = stripslashes($_GET['email']);
  $unlock = stripslashes($_GET['unlock']);
  $numOf = stripslashes($_GET['numOf']);
  
  
  
  $d = mysql_connect($host, $user, $password);
  if (!$d) {
      header($header.': Could not connect: '.mysql_error());
      exit();
  }
  
  
  mysql_select_db($db);
  </code></pre>
  
  <p>// THIS IS WHERE I'M STUCK!</p>
  
  <pre><code>$rw_app_id = LAST_ROW(?)+1;
  </code></pre>
  
  <p>//</p>
  
  <pre><code>$q = "INSERT INTO rw_promo_code (id, rw_app_id, code, unlock_code, uses_remaining) VALUES ('$increase', '$rw_app_id', '$email', '$unlock', '$numOf')";
  
  
  
  $result = mysql_query($q);
  if (!$result) {
      die('Invalid query: ' . mysql_error());
  }else{
  
  echo "Entered Successfully";
  
  }
  </code></pre>