Last if of mysql query


/ Published in: PHP
Save to your folder(s)

two ways of doing it. 2nd is best


Copy this code and paste it in your HTML
  1. $new_sql = "select MAX(id) from reviews";
  2. $get_new_sql= mysql_query($new_sql) or die(mysql_error());
  3. $new_id = mysql_result($get_new_sql,"id");
  4.  
  5.  
  6. <?php
  7. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  8. if (!$link) {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11.  
  12. mysql_query("INSERT INTO mytable (product) values ('kossu')");
  13. printf("Last inserted record has id %d\n", mysql_insert_id());
  14. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.