Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Featch ID number from Datsbase

 
webmaster forum
Activity
0%
 
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.
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
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.
 
webmaster forum
Activity
0%
 
New Poster
Posts: 11
Topics: 8
December 18, 2009, 10:43:50 PM

yeah, this is realy help me, thanks
 
webmaster forum
Activity
0%
 
New Coder
Posts: 16
Topics: 7
July 20, 2010, 10:08:31 PM

Try to find a professional in that field
 
webmaster forum
svr2112  Offline
Activity
0%
 
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
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
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.
 
webmaster forum
Activity
0%
 
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)"; 

Network Management Service
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 04, 2012, 07:41:21 PM