0

i was inserted last_id in database at the same time i want to select the last_id in another redirect page.. i was trying the select query but it not coming the last_id... any idea for this

index.php

    // this code is inserted the last_id
 <?php  
      $last_id = mysql_insert_id();
   ?>

model.php

 <? php
    $sql=("SELECT * FROM facility where last_id='".$last_id.'" ");
 ?>

kindly give me any idea for this.. thank you

Saty
  • 22,443
  • 7
  • 33
  • 51
MGS
  • 113
  • 1
  • 15
  • We need to know your data structure. `$last_id` is the last *autoincrement value* from your table - but the column could be called *anything*. What is your table structure (column names) for `facility`? – random_user_name May 03 '16 at 13:56
  • `mysql_insert_id();` is only any use directly AFTER an INSERT has been executed. It returns the Auto incremement ID of the row just INSERTED – RiggsFolly May 03 '16 at 13:57
  • 1
    Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly May 03 '16 at 13:57
  • 1
    Your SELECT query is badly quoted use `$sql = "SELECT * FROM facility where last_id= '$last_id' "); – RiggsFolly May 03 '16 at 14:00
  • `$sql = ("SELECT * FROM facility where last_id = '$last_id' ");` – Narendrasingh Sisodia May 03 '16 at 14:02
  • facility table colum name is last_id – MGS May 03 '16 at 14:06

0 Answers0