Featch ID number from Datsbase |
| |
|
|
|
New Poster Posts: 11 Topics: 8
|
|
|
December 17, 2009, 11:25:56 PM
|
|
Hello Everyone!
I have made one registration system that can send an email with registered data to the administrator and to the user.
now my problem is that how can i know the ID number of the new user registred in my database, that have auto increase function, and display it in the email that the system will send?
$checkid = mysql_query("SELECT id FROM form1 WHERE id='$id'");
$message2 = "Your ID: $id"
any one can please help me to solve this problem
Thanks in advance.
|
|
| |
|
|
|
Code Guru
Location: India
Gender:  Posts: 1387 Topics: 105
|
|
|
December 18, 2009, 12:15:48 AM
|
|
Before inserting a new record in the database, fetch the last ID OR maximum ID from the database. Now after inserting the record, you can easily increase the already fetched MAX ID by 1.
This will be the new ID of newly added record in the database.
Hope this helps you.
|
|
| |
|
|
|
New Poster Posts: 11 Topics: 8
|
|
|
December 18, 2009, 10:43:50 PM
|
|
yeah, this is realy help me, thanks
|
|
| |
|
|
|
New Coder Posts: 16 Topics: 7
|
|
|
July 20, 2010, 10:08:31 PM
|
|
Try to find a professional in that field
|
|
| |
|
|
|
New Poster Posts: 8 Topics: 0
|
|
|
August 16, 2010, 04:29:52 AM
|
|
first . . we will assume that you have the following:
1. a textbox called MyTextBox 2. a database called MyDB with one table called PersonalData. 3. PersonalData has two columns, one is called ID and the other is called MyName. 4. To connect to a database, you needs a username YASSER and password 123456 5. your database is hosted on your computer! (localhost) 6. in your C#, you imported namespaces: System. Data , System. Data. SqlClient.
Are we ok till now?
Ok, now for the coding ! (this is not the 100% correct way to do it in C# 3. 5, but this is just a starter)
1. you must create a connection object:
SqlConnection con = new SqlConnection();
2. you give that connection the connection string it needs to connect to your database:
con. ConnectionString = "Data Source=localhost;Initial Catalog=MyDB;Persist Security Info=True;User ID=YASSER;Password=123456";
3. define a string variable that will hold the SQL statement that you will use with your database:
string sql = "select * from PersonalData";
4. create a Database Adapter that will connect you to the database, you will pass your connection and sql statement to it:
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
5. creat a dataset that will hold your tables:
DataSet ds = new DataSet();
_________
Insurance | Accident Insurance
|
|
| |
|
|
|
Code Guru
Location: India
Gender:  Posts: 1387 Topics: 105
|
|
|
August 16, 2010, 04:36:27 AM
|
|
@svr2112: Thank you for posting the code. But the code is in C# and the this thread is talking about PHP and mySQL.
There fore the code is not very helpful in this section and you have just posted about how to generate dataset object but did not gave any hint about how to use it.
|
|
| |
|
|
|
Skilled Coder Posts: 125 Topics: 0
|
|
|
March 02, 2011, 01:38:37 AM
|
|
For Fetching ID number form database you have to write one query as given below.
string sql = "select (Field Name) from (Table Name)";
|
|
| |