Jump to content

yesm

Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Posts posted by yesm

  1. You can access the id of data inserted to a MySQL table, by storing the value of mysql_insert_id() to a session var. Make sure the table has a AUTO_INCREMENT option assigned to it (in my case 'member_id). This way you can pass the value on to the next page. Here is a sample script:

     

    <?php

     

    // Start a session and connect to MySQL

    session_start();

    db_connect();

     

     

    // Make query

    $query = "INSERT INTO members ( username, password ) ";

    ."VALUES ( '$u', '" . md5( $p . "' )";

     

    // Run query

    $result = mysql_query( $query );

     

    if ( $result ) { // If the query was succesful

    // Store the row id in session var

    $_SESSION['member_id'] = mysql_insert_id();

    $rows_aff = mysql_affected_rows();

    echo "$rows_aff row affected.";

    } else {

    echo "0 rows affected.";

    }

     

    ?>

     

    Script to print the value on the next page:

     

    <?php

     

    // Start the session to access its values

    session_start();

     

    // Print value

    echo $_SESSION['member_id'];

     

    ?>

     

    I hope this solve your problems :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.