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?
Ray PaseurConnect With a Mentor Commented:
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

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.