Sessions for project setup form

Hello,

I am creating a form/screen that allows users to set up new projects. When a user opens the page and makes a few selections, a project number is provided in a box at the top of the screen.
The project number is created based on a php function that queries the project table in the database for the last number inserted and basically adds a 1.

However, I am running into a problem where multiple users access the form/screen and they are being provided with the same project number. I would like for each user to receive a different project number.

-From the description above, do you think incorporating sessions would be the best approach to handling my issue? I’m also open to any another alternatives.

Here is my function:
[php]function get_max_prj_id(){
//Initialize the return
$job_data = “”;
//get max project id
$sql = “select
max(id)
from projects”;
$rs = get_rs_array(db_name, $sql);
$rc = count($rs);
for ($x = 1; $x <= $rc; $x++) {
if ($rs[$x-1][0] != “”) $job_data = $rs[$x-1][0];
}
return $job_data + 1;
}[/php]

Thanks!

If you had the project number field to be auto incrementing in MySQL, then you can use the mysql_insert_id function to get the last ID created (which will be the one of the record you just made):

[php]mysql_query(‘INSERT INTO…’);
$project_number = mysql_insert_id();[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service