Mysql new entry - give me 'id' in php

  • Zielak69
  • Novice
  • Novice
  • Zielak69
  • Posts: 21
  • Loc: Poland

Post 3+ Months Ago

Hi,

I'm making php script that posts new entry in mysql, the form of it is in flash which sends the data over to php in $_POST. Is it possible to make php script return under what 'id' that new entry has been saved?

The flash is a christmas card where first you put some text, click send and then it should display a direct link (with that 'id') to saved x-mas card, example: 'site.com/card.php?id=312'.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Zielak69
  • Novice
  • Novice
  • Zielak69
  • Posts: 21
  • Loc: Poland

Post 3+ Months Ago

Never mind, I just out that mysql_insert_id(); is the think I was looking for.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

Sorry I didn't see this topic sooner. mysql_insert_id() is exactly what you're looking for, as you've already discovered ;)
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Funny thing, the other day I was busy testing stuff and adding records. deleting records, updating records in my MySql DB and mysql_insert_id() returned an incorrect value for me, I was busy on my site and editing the DB through MySql Query Browser and I screwed something up so I had to reset the values for the auto_increment fields in both tables I was working on ... just look out for something like that ...
  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

mysql_insert_id() returns the auto_increment id of the LAST insert query on that connection. If you have a busy site and you're maintaining connections, it is possible that you have two get the same id....


Page 1 -> Insert Query
Page 2 -> Insert Query
Page 1 -> Insert_id?
Page 2 -> Insert_id?

No good.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 119 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.