title: how to get the last inserted id and how to check in where condition to update query using php
body: <p>Hi iam inserting the data into database table and redirecting to another page and need to insert the details  into the same table by comparing ids and email.But how to get the last inserted id and compare in where condition to update the details.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>index.php</strong>  </p>
  
  <pre><code>&lt;form method="post" action="properties.php" id="myform"&gt;
  &lt;input  type='hidden' value="&lt;?php echo $username; ?&gt;" name='email'&gt;
  &lt;tr&gt;&lt;th&gt;Interest Paid&lt;/th&gt;&lt;td&gt;&lt;input type="text" name="house_interest_paid" value=""/&gt;&lt;/td&gt;
  &lt;tr&gt;&lt;th&gt;Total Interest Paid&lt;/th&gt;&lt;input type="text" name="house_total_interest_paid" value=""/&gt;&lt;/td&gt;
  &lt;tr&gt;&lt;th&gt;House Number&lt;/th&gt;&lt;input type="text" name="house_number" value=""/&gt;&lt;/td&gt;
  &lt;tr&gt;&lt;th&gt;Street&lt;/th&gt;&lt;input type="text" name="house_street" value=""/&gt;&lt;/td&gt;
  &lt;button type="submit"  class = "large awesome yellows" onClick="document.location.href='ownerproperty.php'"&gt; Specify Co-owners Property&lt;/button&gt; &lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>properties.php</strong> </p>
  
  <pre><code>$email=$_POST['email'];
  $interest=$_POST['house_interest_paid'];
  $interestpaid=$_POST['house_total_interest_paid'];
  $number=$_POST['house_number'];
  $street=$_POST['house_street'];
  $query=mysql_query("INSERT INTO house_details(email,house_interest_paid,house_total_interest_paid,house_number,house_street)values           ('$email','$interest','$interestpaid','$number','$street')");
  if($query)
  {       
      session_start();
      header("Location:ownerproperty.php");       
  }
  else{
      echo "Registration has not been completed.Please try again";
  }
  </code></pre>
  
  <p><strong>ownerproperty.php</strong></p>
  
  <pre><code>&lt;form style="display:none" method="POST" action="owner.php"&gt; 
  &lt;h2&gt;Owner Property details&lt;/h2&gt;              
  &lt;input type='hidden' value="&lt;?php echo $username; ?&gt;" name='email'&gt;
  &lt;?php include "ownership.php"; ?&gt;
  &lt;p&gt;&lt;label for="name_coowner"&gt;Coowner Name&lt;/label&gt; &lt;input value="&lt;?php echo $row['name_coowner'];?&gt;" type="text"    name="name_coowner"  /&gt;&lt;/p&gt;
  &lt;p&gt;&lt;label for="pan_coowner"&gt;PAN Of Coowner&lt;/label&gt; &lt;input value="&lt;?php echo $row['pan_coowner'];?&gt;" type="text"   name="pan_coowner"  /&gt;&lt;/p&gt;            
  &lt;button type="submit"  class = "medium" style="background-color: #2daebf;"&gt;Save&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Ownership.php</strong></p>
  
  <pre><code>$res = "SELECT * FROM house_details 
     WHERE email ='$username'";
  $result=mysql_query($res);
  $row = mysql_fetch_array($result);
  </code></pre>
  
  <p><strong>Owner.php</strong></p>
  
  <pre><code>$email=$_POST['email'];
  $owner_name=$_POST['name_coowner'];
  $pan_owner=$_POST['pan_coowner'];
  $query=mysql_query("UPDATE house_details SET name_coowner='$owner_name',pan_coowner='$pan_owner'
                        WHERE email='$email' AND house_details_id='2'");
  if($query)
  {       
      session_start();
      header("Location:rentalproperty.php");          
  }
  </code></pre>
  
  <p>For the first time when i click on submit button the data is inserting into db and redirecting to ownerproperty.php .in that i need to get the inserted id and need to comapre that id and email and need to update the owner property details in the same column when the email and id are same.But how to get that id and compare in the where condition can anyone help me.</p>