mysql - how to get the last inserted id and how to check in where condition to update query using php -
hi iam inserting data database table , redirecting page , need insert details same table comparing ids , email.but how last inserted id , compare in condition update details.
here code:
index.php
<form method="post" action="properties.php" id="myform"> <input type='hidden' value="<?php echo $username; ?>" name='email'> <tr><th>interest paid</th><td><input type="text" name="house_interest_paid" value=""/></td> <tr><th>total interest paid</th><input type="text" name="house_total_interest_paid" value=""/></td> <tr><th>house number</th><input type="text" name="house_number" value=""/></td> <tr><th>street</th><input type="text" name="house_street" value=""/></td> <button type="submit" class = "large awesome yellows" onclick="document.location.href='ownerproperty.php'"> specify co-owners property</button> </span> </form> properties.php
$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 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"; } ownerproperty.php
<form style="display:none" method="post" action="owner.php"> <h2>owner property details</h2> <input type='hidden' value="<?php echo $username; ?>" name='email'> <?php include "ownership.php"; ?> <p><label for="name_coowner">coowner name</label> <input value="<?php echo $row['name_coowner'];?>" type="text" name="name_coowner" /></p> <p><label for="pan_coowner">pan of coowner</label> <input value="<?php echo $row['pan_coowner'];?>" type="text" name="pan_coowner" /></p> <button type="submit" class = "medium" style="background-color: #2daebf;">save</button> </form> ownership.php
$res = "select * house_details email ='$username'"; $result=mysql_query($res); $row = mysql_fetch_array($result); owner.php
$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' email='$email' , house_details_id='2'"); if($query) { session_start(); header("location:rentalproperty.php"); } for first time when click on submit button data inserting db , redirecting ownerproperty.php .in need inserted id , need comapre id , email , need update owner property details in same column when email , id same.but how id , compare in condition can me.
properties.php
$query=mysql_query("insert house_details(email,house_interest_paid,house_total_interest_paid,house_number,house_street)values ('$email','$interest','$interestpaid','$number','$street')"); $id = mysql_insert_id(); //for last inserted id. if($query) { session_start(); $_session['sess_id'] = $id; // set 1 session variable last inserted id. header("location:ownerproperty.php"); } owner.php
<?php session_start(); // start session $id = $_session['sess_id']; // use id in query $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' email='$email' , house_details_id='2'"); if($query) { session_start(); header("location:rentalproperty.php"); } [note : mysql extensions deprecated. use pdo or mysqli_ database extensions.]
Comments
Post a Comment