Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Get id of newly created database entry

Hi

I am wrinting a registration system for my students in php. I have a form that gets submited with all the info but I want certain things to get registered in the background based on selections in the form. I cant always trust that student numbers will be unique so I want to retrieve the unique id no created for the person by the mysql db.

Logic says submit the user to the db and then immediatly query the id to a variable once created. My problem is what if there is a duplicate name or student number already. Should I
just check for that before submitting or is there a better way to do this.

Tx
Quintus
0
QuintusSmit
Asked:
QuintusSmit
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
Yes, you need to check before you INSERT and if there is already an entry, make it an UPDATE instead.  PHP/MySQL has 'mysql_insert_id()' which will return the last id for an AUTO_INCREMENT column.  http://us.php.net/manual/en/function.mysql-insert-id.php
0
 
QuintusSmitAuthor Commented:
Perfect! Thank you very much
0
 
QuintusSmitAuthor Commented:
Dave - could you pls have a look at  this question

http://www.experts-exchange.com/Database/Miscellaneous/Q_27382125.html

tx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now