Mysql Insert Id

mysql_insert_id() :-

mysqli_insert_id() function returns the id generated by a your query on a table with a column having the AUTO_INCREMENT attribute.

Performing an INSERT or UPDATE statement using the LAST_INSERT_ID() function will also modify the value returned by the mysqli_insert_id function.

$result = mysqli_query($con, $qry);
$userid = mysqli_insert_id($con); // it auto generate the pro_id which you want to insert into product size table as a froegin key.
//echo "user id = ".$userid;
$prosize = $_POST['size'];
$qry1 = "insert into product_size (pro_size, user_id) values('$prosize','$userid')";
echo $qry1;
$result1 = mysqli_query($con, $qry1) or die(mysqli_error());
if($result1)
{
echo "successful";
}
else {
echo "error";
}










Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial