making a notify me of replies code

ok i have made my own forum and im currently creating a notify me of replies part for my forum...

i have come up with the idea of this..

Make a forum_email table..... this has:
mailed (enum y/n)

If a user wants an email when this thread is replied to, insert a row and set mailed to default = n.

Now, when someone makes a reply to this topic, do...

$query = "SELECT fe.*,, FROM forum_email as fe
LEFT JOIN users as u on u.user_id = fe.user_id
WHERE topic_id = '".$this_topic_id."' AND fe.user_id != '".$thepostinguser."' AND mailed='n'";
$res = @mysql_query($query,$link) or die ("sendNotification query fails :".mysql_error());

//nobody wants an email, stop now
if(count($user_id) == 0):

foreach($user_id as $value) {
send emails

//set emailed to 'y' so that they don't get numerous emails... set it back to 'n' when they view this topic
$query_noted = "UPDATE forum_email SET mailed='y' WHERE topic_id = '".$this_topic_topic_id."'";

the problem is if the user is vreating the post and the post id is auto inc how can i get the topic id if its not yet created :@S
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can get the ID of the last insert by using the mysql_insert_id() function.. so... just run the INSERT to create the topic and THEN run

$newPostID = mysql_insert_id();

and now $newPostID has the ID of the newly created topic. You'll just have to run your "email me of replies" code after the topic creation.
runnerjpAuthor Commented:
how would i do this

i tried the code below but it didnt work
		$insertpost = "INSERT INTO forumtutorial_posts(forum,author,title,post,showtime,realtime,lastrepliedto,lastposter) values('$forum','$username','$theSubject','$thePost','$thedate','$thedate','$thedate','$username')";
												mysql_query($insertpost) or die("Could not insert post"); //insert post
												//$insertemail = "INSERT INTO forum_email(user_id,topic_id,mailed) values('$id','$forumpostid','1')";
												//mysql_query($insertemail) or die("Could not insert email"); //insert  email
												$updatepost = "UPDATE `users` SET `post_count`=`post_count`+'1' WHERE `Username`='$username'";
												mysql_query($updatepost) or die("Could not update post");
												$newPostID = mysql_insert_id($insertpost);
												echo $newPostID;

Open in new window

Ray PaseurCommented:
See if this helps... ~Ray

SP: if the query fails to insert, $xyz == FALSE
$insertpost = "INSERT INTO ...";
$xyz = mysql_query($insertpost) or die("Could not insert post"); // RESOURCE ID IS IN $xyz
$newPostID = mysql_insert_id($xyz);
echo $newPostID;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.