Tuesday, 8 August 2017

php - How can i get ID when insert into a table




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 ?


Answer



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.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...