Display Last Created Auto Increment ID

Drakethos

Preordered Sc2 ftw!
Reaction score
56
Hello. I am working on a Social Networking site, that has threads and posts. What am trying to do, is get the ID of the post after it has been created and sent to the data base. I tried using SELECT LAST_INSERT_ID but am unable to return a usable value. I keep getting resource#4. After i get the ID i will add it to the current thread, then send the user to that thread. Right now the thread is not created, and I am just trying to produce the posts and generate a link to that post through: post?postid=(autoincrement number)
When i use mysql_fetch_row, i get :
mysql_fetch_row() expects parameter 1 to be resource, boolean given
Here is some of my code.
Code:
// Creates the post
$result = mysql_query("INSERT INTO `post` VALUES(NULL, '$Title', 'Derrick', '$Post', '$date')");
    if (!result) error_message('Could not send post');

   // $GetPostId = mysql_query("SELECT LAST_INSER_ID()");
$GetPostId = mysql_query("SELECT LAST_INSERT_ID()FROM `post` LIMIT 0 , 1");
    $PostID = mysql_fetch_row($GetPostId);
print($PostId);
I am pressed for time with this and any help is much appreciated and +rep.
 

Drakethos

Preordered Sc2 ftw!
Reaction score
56
The mysql_insert_id works, but it returns 0, i think its how im setting the auto_increment. You said not to use Null, but i couldnt find what to use. I tried just doing ' ' which also gives it 0. Is there something i have to put for the AutoIncrement value, to get an actual value to return?
 

Samuraid

Advisor
Reaction score
81
The mysql_insert_id works, but it returns 0, i think its how im setting the auto_increment. You said not to use Null, but i couldnt find what to use. I tried just doing ' ' which also gives it 0. Is there something i have to put for the AutoIncrement value, to get an actual value to return?
Specify the list of columns in your INSERT statement:

Code:
INSERT INTO table (col1, col2, col3) VALUES (value1, value2, value3)

Just don't specify the auto_increment column when performing the insert.
 

Drakethos

Preordered Sc2 ftw!
Reaction score
56
I did that now, but it is still giving me 0. I need to know what the post is so i can create a link to it, and show it to the user.

EDIT: I have it working now, someone who i had emailed, told me how to get it working: using: list($PostID) = mysql_fetch_array($GetPostID); to get the value through.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> I am working on a Social Networking site

Hehe, good luck. :thup:
 

Drakethos

Preordered Sc2 ftw!
Reaction score
56
Yes, I'm going to need it, I only have until midnight on the 20th before the carriage turns to a pumpkin. Its for a competition. I just hope I can get enough done, to bs my way into getting past Region then the fun work will come.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top