Hi - I am creating a simple PHP Task Request form that will post to an email address. I am fine with everything except one problem. I need this form to generate an ID number which will also display in the Subject line. If someone requests a task and it is number 001, then the next person to request a task using this form is number 002. I would need to have the form write to a database, so that the next number +1 can be generated based on the previous number in the database. Any help is greatly appreciated.
rgracey 0 Newbie Poster
Recommended Answers
Jump to PostBefore writing a next task to the database you read the last task. However, if the user has the form opened in the browser, there might be a problem displaying the current last inserted task ID, since many tasks could have been inserted after opening the form. You can use …
Jump to PostOK, I'll try to generate some steps I think would be appropriate and you then correct me where I might be wrong.
- A user visits a task request form (say get_task.php)
- The form action attribute is e.g. confirmed_task.php
- The user fills-in all the necessary information and submits the form
- The …
Jump to PostI would suggest docket added to db and then id retrieved (last inserted id). It could happen that 2 requests made simultaneously (very unlikely but possible). Only then email msg constructed.
Jump to PostThere should be no need to do a select query to get max id (last row id). You just add with an INSERT and ask for
lastInsertId()
:$sql = "INSERT INTO tasks (col1,col2,col3) VALUES (:val1,:val2,:val3)"; $stmt = $dbh->prepare($sql); $stmt->execute(array(":val1"=>$val1,":val2"=>$val2,":val3"=>$val3)); $lastId = $dbh->lastInsertId();
The
$lastId
…
All 13 Replies
broj1 356 Humble servant Featured Poster
rgracey 0 Newbie Poster
broj1 356 Humble servant Featured Poster
rgracey 0 Newbie Poster
broj1 356 Humble servant Featured Poster
rgracey 0 Newbie Poster
rgracey 0 Newbie Poster
broj1 356 Humble servant Featured Poster

diafol
rgracey 0 Newbie Poster

diafol
lorenzoDAlipio 24 Junior Poster in Training
broj1 356 Humble servant Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.