Jump to content

[SOLVED] php id


Ninjakreborn

Recommended Posts

Say for example, I enter a data into a form.

This form is going into a database.

 

Upon submittal I have

 

<?php
// validate material
// show errors
// if clear clean variables
// database variables
// review form
$id = mysql_insert_id();
// id = last inserted value.
?>

What I am concerned about is this.

 

1. 2 people go to the form.

Both submit at the same time

Can the id on one persons script pickup the id on the record from the other guy if he submitted seconds earlier, I guess that's what I want to know.

 

Or does it ALWAYS refer to the value entered into THAT SPECIFIC script.  I just want to make sure it's reliable, before I use it.

Link to comment
Share on other sites

From the manual.

 

Note:  Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value.

 

Using it the way you want will be unreliable. What exactly are you trying to do?

Link to comment
Share on other sites

I wanted a quicker way to retrieve the id, without doing it the long way.  I am trying to do stuff lately that cuts down on time.

 

Originally you insert something into the database, then you sometimes need to get the id for various purposes.

In this situation, I need to enter the data, get the id and have it available for the review form.

I wanted to see (since I end up needing to do that a lot)

if there was  a better way than a full select statement, query, and variable.

I always do

<?php
$selectid = "SELECT id FROM table WHERE whatever here to show it's the right one;";
$queryid = mysql_query($selectid);
if ($rowid = mysql_fetch_array($queryid)) {
  $id = $rowid['id'];
}
?>

 

This is something I do quite often.

So in essence, if I want the id retrieval to work on that one.  I will probably end up having to do it the long way, if so Oh well, but I saw about this id.  I had someone on here recommend me to go ahead and use that instead, but if it's unreliable, I am not taking any chances.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.