Question

I insert values in a table but I want to get column's id while I am inserting ;
These are my code ;

$addInsurance = mysql_query("INSERT INTO insurance (coo_Country,pod_Country,startDate,finishDate,insGNumber,insKNumber,customer_customer_ID) VALUES ('$cikiscity','$variscity','$baslangicTarih','$bitisTarih','$yetiskin','$cocuk','$customer_id') SET '$ID'=insurance_ID");
if (!$addInsurance) {
    echo'Could not run query' . mysql_error($connection);
}

I want to get insuranse_ID in insurance Table how can I do it ?

Was it helpful?

Solution

Do this on your else statement:

else {
  echo mysql_insert_id();
}

Though I do not recommend it because MySQL extension is deprecated in newer versions of PHP. Generally to issue queries to MySQL programmers use the MySQLi or the PDO extension of PHP. Try doing it using MySQLi if you can. It's equivalent is the mysqli_insert_id() function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top