Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:29:57+00:00 2026-05-31T12:29:57+00:00

Using this php code: try{ $dbh = new PDO(mysql:host=$host;dbname=$dbname,$user,$pass); $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); //

  • 0

Using this php code:

try{
    $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
    // INSERT CLEAN DATA INTO TABLE…
    $sth = $dbh->prepare("
    INSERT INTO Fan(fanNm,fanEmail,fanPass,fanDynamSalt)
    VALUES('$userName','$userEmailAddress','$userPassword','$dynamSalt')"
    );
    $sth->execute();
    ////////////////////////////////////////////////////////////////////
    ## Set Session Var for this PK ID in Fan table that is being created ##
    ////////////////////////////////////////////////////////////////////
    $_SESSION['newUserSessID'] = mysql_insert_id();
    echo "<strong style='color:#fff;'>".$_SESSION['newUserSessID']."</strong>";
} //try

catch(PDOException $e){
        echo "Oops, We're experiencing an error.";
        file_put_contents('/PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
} //catch

It inserts FINE into the database, but I am using echo "<strong style='color:#fff;'>".$_SESSION['newUserSessID']."</strong>"; to echo out that value and it ALWAYS returns a zero.

Even if I run :

SELECT LAST_INSERT_ID( ) 
FROM Fan
LIMIT 0 , 30

It gives me output like

0
0

(since there is two rows in database table)

Anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:29:58+00:00Added an answer on May 31, 2026 at 12:29 pm

    You should not use mysql_insert_id as that isn’t part of PDO (which is what you’re using to interact with the database in this instance).

    Instead use PDO::lastInsertId():

    $_SESSION['newUserSessID'] = $dbh->lastInsertId();
    

    More info: http://www.php.net/manual/en/pdo.lastinsertid.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this PHP code: if (isset($_GET['c'])) { $pages = array(home, upload, signup);
I am using this code to send mail with php http://www.siteduzero.com/tutoriel-3-35146-e-mail-envoyer-un-e-mail-en-php.html#ss_part_4 . This code
implementing publishActivity in PHP using the REST API using this code: $activity = array(
So I'm using this code: <iframe src=http://www.connect.facebook.com/widgets/fan.php?href=http://www.facebook.com/pages/TopDesenecom/148037301911330&width=205&height=256&show_faces=true&stream=false&header=false&css=http://topdesene.com/template/fb.css></iframe> and facebook shows this code: <link href=http://external.ak.fbcdn.net/fbml_static_get.php?src=http%3A%2F%2Ftopdesene.com%2Ftemplate%2Ffb.css&appid=148037301911330&pv=1&sig=59bf9a037df3a88cb6ff142f25227177&filetype=css&cb=2
I'm using this plugin: http://www.jeremymartin.name/projects.php?project=kwicks And my code follows this example: http://www.jeremymartin.name/examples/kwicks.php?example=7 I'm using
I'm trying to parse an xml file with PHP. I'm using this code and
i have this simple code to load data from other php page using get
Ho to make this simple xml with php using DOM? Full code will be
I'm makin' a scripting language interpreter using PHP. I have this code in that
I'm using this code to submit a form to a php script: var valid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.