0

I want to retrieve the latest autoincremented id of the record which i have inserted, so that i can use it update query.
I used last_insert_id() but it seems to be not working.Please help as i m still learning PHP

here's the code..

$insert = "INSERT INTO `farmlogin` (`uid`, `name`, `gender`, `date`, `age`, `bb`, `htno`, `htunit`, `lno`, `lunit`, `pric`, `clr`, `insured`,
 `inscomp`, `polname`, `premiumtype`, `premiumamt`, `insstdate`, `matdate`, `remk`) VALUES ('$d', '$n', '$gen', '$dt', '$umar', '$bo', '$hgt', '$unitht', '$lgt', '$unitl', '$pr', '$colo', '$check', '$cname', '$poly', '$premtype', '$amt', '$insurancedat', '$mat', '$rk')";
$result = mysql_query($insert);


$id = intval($_GET['id']);
$sql = "UPDATE `farmlogin` SET `doccity`='$id' WHERE `cowid`='last_insert_id($result)'";
echo "$sql";
$data = mysql_query($sql);


    if($result)
    {
        echo "<script>location.href='http://localhost/assigndoc.php'</script>";
    } 
    else
    {
        echo "sami";
    }

Edited by Reverend Jim: Fixed formatting

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by pritaeas
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.