can any body tell me how to get the Current Value of Auto_increment??
can we create sequences in PHPMYADMIN if yes then how and also how to get its current value???
hello mohsin1122,
please explain you problem in detail with some part of code.
i think you are looking for get the last inserted record id.
this can be done using below query
SELECT id FROM tablename WHERE ORDER BY id DESC LIMIT 1;
i hope this will helpful for you.
SR
bro
i dont want user to insert ID by himself
instead i make that field readonly and want that when user click on registration form link and when form loads
the next avilable record is already shown in it
tell me how to get that current auto increment value
if i use the last record id and if the last record was deleted
e.g
5 abc [email protected]
6 xyz [email protected]
the next value id should be ‘7’
if the rec 6 is deleted and i use the last record id then it would again show me 5+1=6 in user id
instead i want it to show me 7 value which is according 2 the sequence
hello mohsin1122,
that’s fine,
you just need to modify your insert query. post your insert query here. so i can provide you answer
SR
here it is
[php]
$sql= “INSERT INTO employees
(FirstName, LastName, Title, EmailName, Extension, WorkPhone, BillingRate)
VALUES(’$_POST[FirstName]’, ‘$_POST[LastName]’, ‘$_POST[Title]’, ‘$_POST[EmailName]’, ‘$_POST[Extension]’, ‘$_POST[WorkPhone]’, ‘$_POST[BillingRate]’)”;
if (!mysql_query($sql))
{
die('Error: ’ . mysql_error());
}
echo “1 record added”;
[/php]
hello mohsin1122,
it’s looking fine.
what error you getting when execute this code?
SR
ive got no error in executing this
my problem is in showing
[code]<input name=“EmployeeID” type=“text” id=“EmployeeID” value="<?php $query = mysql_query("SELECT EmployeeID FROM employees ORDER BY EmployeeID DESC LIMIT 1 ") or die(mysql_error());
$row = mysql_fetch_array( $query );
echo $row[‘EmployeeID’]+1; ?>" size=“11” maxlength=“11” readonly=“readonly” />[/code]
it shows the Employee ID of last record + 1 to make it next value
but consider in a situation where
the last record is 10 so the text box shows 11 value init
i want that text box should show me the auto increment current value let suppose the auto increment id is now on 15
i want that it show me 15 value instead of 11
thats my problem
Guys, in my opinion, you should never use “Auto-Increment” the way you are attempting to.
First, what happens if two users register at the same time and both get id+1??? Errors abound!
What you should do is just hide the ID number and then, once they have registered, read the ID that was set by the database’s auto-increment and display it. Like "You have been entered into our system. Your new ID number is: " $ID… or something like this. Then, there is NEVER any issues with setting their ID number.
Most programmers never give that unique number out anyways. Usually it is just used behind the scenes.
All the users actually needs is his UserID (Name he gives for it) and his password. Then, the database creates the hidden ID number using Auto-Increment and your system can use that for accessing the database, but, the user never needs to know it.
Hope those thoughts help some… (Just my opinion…) Good luck with it…
hmmm
I know that’s the last option thanks for suggestion
but i want to tell you its not a public registration page on that page only 1 person can do registrations .
any way thanks again
Well, perhaps we were not clear. You can do it that way if you wish. What you would do, is first do the query that Sarthak mentioned. That would pull the last number, then, add one to it and insert it. The only issue with this is if you use the auto-increment INSIDE a database, you really can not access that for writing. It is created by the database system, not you. You could just NOT use auto-increment and do it yourself. Very easy. Just use that same query, add one to it as mentioned then, insert it. The number would be displayed as a label on the page and not changeable by the user… Did that make sense to you? Hope so…