Reputation: 69
I have website in which i feed daily entry of complaint forms , Now we don't assign form number to any from, in database from number is a id of all from and it auto generated by database but i want show this id on a html from before from submitted ,
like if i click new from on my web site it will show all filed empty except form no filed it'll be filled by auto generated from no , and when its submitted it'll take this from no as id if it'll be available that time ,
Upvotes: 0
Views: 1981
Reputation: 24002
I suggest to use UDF (User Defined Function) to achieve this.
Submitting a pre-filled value into an auto-incremented value may result an exception if multiple forms, by different user, with same number are submitted. There would be a constraint violation.
Instead you can depend on UDF for sequences on required table field.
You may require:
nextval
to generate next sequence number record
into the table.curval
to fetch current sequence number record
from the table.nextval
function to fill your form for "Form Number"
field.This procedure is safe on concurrent submissions.
Refer to similar discussion and an example at:
Upvotes: 1
Reputation: 888
try this one
$ids =mysqli_num_rows(mysqli_query($con,"SELECT MAX(id) from mytable"));//con is connection variable
if(!empty($ids[0]))
$form_no = $ids[0]+1;
else
$form_no = 1;
Upvotes: 0