-4
$run = $con->query ( $query );
$id = mysql_insert_id ();


//find category Name
    $category = $_REQUEST ['category'];
    $run1 = $con->query ("select * from category where id='$category'");
    $run2=$run1->fetch_array();
    $category=$run2['category'];
    
//find  subcategory Name
$run11 = $con->query ("select * from subcategory where id='$subcategory'");
$run21=$run11->fetch_array();
$subcategory=$run21['subcategory'];
ysth
  • 96,171
  • 6
  • 121
  • 214
Arjun M
  • 1
  • 1
  • What type is `$con`? – Progman Oct 25 '20 at 21:28
  • 2
    your cod eis **vunerable** to **sql injection** so use only **prepared statements with paramaters** – nbk Oct 25 '20 at 21:30
  • 1
    Reading the [PHP Manual](https://www.php.net/manual/en/mysqli.insert-id.php) will be an invaluable experience to learn about these transitions. – Martin Oct 25 '20 at 21:31
  • If you are changing the old mysql_* API then I would recommend changing it to PDO. Why bother with mysqli? – Dharman Oct 25 '20 at 21:37

1 Answers1

-1

See mysqli::$insert_id. mysql_insert_id() was part of the now deprecared mysql-extension.

slaakso
  • 8,331
  • 2
  • 16
  • 27