Jump to content

Recommended Posts

Okay I am doing some finishing touches on this script. It is a review script. Here is how it works:

 

1.User Types a Review

2.Script sends out a email verification to user

3.After email is verified, Review goes into pending, and sends a email to admin

4.Admin either accepts review, or denies it.

5.Script sends out a email to the user telling them they have been accepted or denied.

 

Telling you guys how this works, might help you help me.

 

In the script, after step 1 it adds a record to the database, but I need to know the id before it is added for the URLs, so I made a function that generates the ID from getting the last entry plus one. Here is that function:

 

<?php
function getId(){
$q = mysql_query("SELECT MAX(id) FROM `reviews`");
$f = mysql_fetch_array($q);
return $f['0']+1;
}
?>

 

Does my systems with the IDs sound stable, or should I go a different route of some sorts?

Link to comment
https://forums.phpfreaks.com/topic/169496-stability-question/
Share on other sites

Does my systems with the IDs sound stable

 

Nope. If you have multiple concurrent visitors you cannot guarantee that the number you just got that way will be the next available id at that time you use it.

 

You need to actually insert a row first, then get the id of that row (mysql_insert_id) in order to guarantee that the id is accurate for all concurrent instances of your script.

Link to comment
https://forums.phpfreaks.com/topic/169496-stability-question/#findComment-894295
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.