Featch ID number from Datsbase

Discussion in 'PHP/MySql' started by amber.long, Dec 18, 2009.

Remove these ads by signing in
Remove these ads by signing in
Thread Status:
Not open for further replies.
  1. amber.long New Member

    Member Since:
    Jun 20, 2009
    Message Count:
    29
    Likes Received:
    1
    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.
  2. SeoKungFu Active Member

    Member Since:
    Jul 10, 2009
    Message Count:
    604
    Likes Received:
    77
    Occupation:
    SEO Ninja
    From what I get from your question ( sorry, but you could have stated it a bit clearer ) you might need to fetch the last inserted id right after the insertation of a new user data, check this out : PHP: mysql_insert_id - Manual
  3. mp3 search New Member

    Member Since:
    Dec 17, 2009
    Message Count:
    2
    Likes Received:
    0
    hello

    with what i understand you just want to get data from your database right?

    make like this

    first make a connection to your db . i like to put it in function

    <?php

    function db_connect()
    {
    $db = new mysqli('localhost','username','password','database name');
    if(!$db)
    {
    echo "cannot connect to database right now";
    }
    else
    {
    return $db;

    }
    }

    ?>

    then call the db like this

    <?php

    $con = db_connect(); //connect to your database

    $query = "select * from form1 where id= '$id'"; // make a query
    $get_query = $con->query($query); // search the query

    where($row = $get_query->fetch_assoc())
    {
    $data = $row['id']; // id is your column table that you want to fetch
    echo $data; // get output data

    }

    ?>
    i hope this its help. sorry if my english is not good
  4. amber.long New Member

    Member Since:
    Jun 20, 2009
    Message Count:
    29
    Likes Received:
    1
    Thanks for the help..This is exactly what i needed.
Thread Status:
Not open for further replies.

Share This Page