rEhSi_123 Posted March 24, 2009 Author Share Posted March 24, 2009 tbh im not really sure what that script you show is for. It looks like that is a reply to a reply. But I have noticed a couple of errors there. 1)You are trying to echo out $id but you havnt given $id a value. 2)You are looking for a forum_reply where the id is equal to the topic id or tid. Is this correct? Or should you be looking for the actual topic id to be the same? Can you post the actual html form that sends to this script so that I can see what you need to get/change/insert etc.. I think what has happened is your values are totally mixed up, its difficult to see what needs doing unless I am at your computer and can see everything. Mate what can I say the 'tid' has been solved....... This is what my link was doing........haha <a href=\"index.php?act=test&id=".$rowr['id']."\"><img src=\"quoteIcon.gif\"></a> changed it to this <a href=\"index.php?act=test&id=".$rowr['tid']."\"><img src=\"quoteIcon.gif\"></a> So basically it was calling id of the comment instead of tid But one little problem left is that the value inside the reply_id is ZERO...... Think I need this $reply_id = $_GET['original_post_id']; Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793196 Share on other sites More sharing options...
fry2010 Posted March 25, 2009 Share Posted March 25, 2009 awesome glad u sorted it, i bet you feel a lot better now lol. Yeah grab the value of the original id and put that into your table and bobs your uncle. Nice going. Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793231 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 awesome glad u sorted it, i bet you feel a lot better now lol. Yeah grab the value of the original id and put that into your table and bobs your uncle. Nice going. Well I was feeling better untill now the reply_id is taking in the value of the 'tid' things never get better for me i guess...... :'( This is how my code stands.....how could I fetch the original ID of the comment...please advice <?php if(!$_SESSION['uid']){ header("Location: index.php"); } $msg = mss($_POST['reply']); $tid = mss($_GET['id']); $reply_id = $_GET['id']; if($tid){ $sql = "SELECT * FROM `forum_topics` WHERE `id`='".$tid."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "This topic does not exist!"; }else { $row = mysql_fetch_assoc($res); $sql2 = "SELECT admin FROM `forum_replies` WHERE `id`='".$row['cid']."'"; $res2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($res2); if(!$_POST['submit']){ echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."\">\n"; echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n"; echo "</table>\n"; }else{ if($row2['admin'] == 1 && $admin_user_level == 0){ echo "You do not have sufficient priveleges to add a reply to this topic"; }else { if(!$msg){ echo "You did not supply a reply"; }else { if(strlen($msg) < 10 || strlen($msg) > 10000){ echo "Your reply must be between 10 and 10,000 characters!"; }else { $date = date("d-m-y") ." at ". date("h-i-s"); $time = time(); $sql4 = "INSERT INTO `forum_replies` (`id`,`tid`,`uid`,`message`,`date`,`time`,`reply_id`) VALUES('".$id."','".$tid."','".$_SESSION['uid']."','".$msg."','".$date."','".$time."','".$id."')"; $res4 = mysql_query($sql4) or die(mysql_error()); //$sql5 = "UPDATE `forum_replies` SET `reply_id` = '".$reply_id."' WHERE `message` = '".$msg."'"; //$res5 = mysql_query($sql5) or die(mysql_errno()); header("Location: ./index.php?act=topic&id=".$tid); } } } } } } ?> Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793240 Share on other sites More sharing options...
fry2010 Posted March 25, 2009 Share Posted March 25, 2009 First are you able to explain why you have this: $id in your statment for : $sql4 Because it seems like your not even giving $id a value, yet you say its inserting the $tid value... Anyway ...how to get the original id? echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."\">\n"; I assume that is the form for the user to enter a reply. You need to put the original id of the post into this and get it with: $reply_id = $_GET['reply_id']; When you output the original message you will need to include the id for it. If you dont do this the only other way to select the id is to use an sql query as such: $sql = "SELECT id FROM forum_messages WHERE msg = '$msg'"; Trouble is though as the database grows it might be slow to do this, im not 100% sure though as iv never built a forum before let alone had loads of data in the database. Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793252 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 First are you able to explain why you have this: $id in your statment for : $sql4 Because it seems like your not even giving $id a value, yet you say its inserting the $tid value... Anyway ...how to get the original id? echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."\">\n"; I assume that is the form for the user to enter a reply. You need to put the original id of the post into this and get it with: $reply_id = $_GET['reply_id']; When you output the original message you will need to include the id for it. If you dont do this the only other way to select the id is to use an sql query as such: $sql = "SELECT id FROM forum_messages WHERE msg = '$msg'"; Trouble is though as the database grows it might be slow to do this, im not 100% sure though as iv never built a forum before let alone had loads of data in the database. Right mate......did some changes and I think I am almost there.....assumingly..... Anyways for my links this is what I did: echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['tid']."&reply_id=".$row['id']."\">\n"; Now in the above when I hover my mouse over the link button I can see that id='tid' and reply_id='id_of the comment' So I echoed the reply_id on the form to check the value and yes it is echoing the right value on the form..... Now how should I design my insert statement as this is how it sits..... if($reply_id){ $date = date("d-m-y") ." at ". date("h-i-s"); $time = time(); $sql4 = "INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`,`reply_id`) VALUES('".$tid."','".$_SESSION['uid']."','".$msg."','".$date."','".$time."','".$reply_id."')"; $res4 = mysql_query($sql4) or die(mysql_error()); header("Location: ./index.php?act=topic&id=".$tid); N.B: cant explain the id in my previous statment as I was trying the method of hit and trial..... Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793264 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 Further update! Even though it is echoing the right reply_id it is inserting the value of tid inside the database. echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."&reply_id=".$row['id']."\">\n"; The above echo statement is used inside the form where the user enters the details.....now even though the link says act=test&id=".$row['tid']."&reply_id=".$row['id'] if I change the 'id' to 'tid' the form is blank suggesting there is no value for tid........ Anyways I am not able to understand why the reply_id is taking in the value of tid..... even though if i put this SQL statement at the botton of my code: $sql5 = "UPDATE `forum_replies` SET `reply_id`='".$reply_id."'"; $sql5 = mysql_query($sql5) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793276 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."&reply_id=".$row['id']."\">\n"; I am pretty much sure this is problem where the user enters the reply......... Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793300 Share on other sites More sharing options...
fry2010 Posted March 25, 2009 Share Posted March 25, 2009 it is taking the value of tid because you have set in it id which is the same as the id = id part. So they will be the same. In the part that you are producing the original post i.e. where it alll starts from, echo out the id of that to see if you get a value. If you get a value, then you need to store that value for when a user replies to it. Then set this to the reply_id and get this value. Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793316 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 If you get a value, then you need to store that value for when a user replies to it. Then set this to the reply_id and get this value. Mate I am not sure on how to do this part. It is echoing out id value which is the tid. Could you please explain in php. Thanks Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793387 Share on other sites More sharing options...
fry2010 Posted March 25, 2009 Share Posted March 25, 2009 sound like that is the 'topic id' maybe? Well... you need to put the original id of the post in there. How are you actually displaying the original post? You must have something there that is echoing out the original message. So you might have something like: $sql = " SELECT * FROM blah blah blah"; $res = mysql_fetch_array($sql); while($res = fetch()) { echo $res['msg'].'<br />'; just add this: echo $res['id']; } That should echo out the message and the id for that message. Then just put this into your form so maybe: <form method="post" action="reply_script.php?original_id='<?php echo $res['id']; ?>'"> <input blah blah.... </form> But try to put that into the while loop. Then in the script that gets this reply grab the value $original_id = $_GET['original_id']; Other than that i really cant tell how to get it to work. sorry. Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793398 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 $sql = " SELECT * FROM blah blah blah"; $res = mysql_fetch_array($sql); while($res = fetch()) { echo $res['msg'].'<br />'; just add this: echo $res['id']; } Hmmm i actually dont have a while loop in my code!!!! Also I echoed the ID of comment and it is comming out right as I have this $id = $_GET['reply_id']; in my code........ So basically I am just not sure if this part of the code html form is right????? echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."&reply_id=".$row['id']."\">\n"; bacause as you said before, it is geting id = id..... Let me begin from the start............. 1. User see a comment and decides to reply to it...... 2. He then click on the link and this is what is displayed on the address bar</li> http://localhost/login/index.php?act=test&id=13&reply_id=54 Now, id=13 is of the topic id which is spot on! and reply_id=54 is of the message id which is also spot on! 3. After the user enters the message he then clicks on this link</li> /index.php?act=test&id=".$row['id']."&reply_id=".$row['id']."\">\n"; I think it is here which equals the topic id with message id.......???? and hence i get the value of topic id......... Also bro I dont have a select statement for obtaining the id of the message like $sql = "SELECT * FROM `forum_replies` WHERE `id` = '".$id."'"; Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793495 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 Dude I dont know if this is right or wrong........but this adjustment worked..... echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."&reply_id=".$reply_id."\">\n"; :o :o :o :o :o The reply_id section is now taking in values of previous messages......... Now only thing is to quote the previous message in the text box! like below when replying to a comment. hello Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793512 Share on other sites More sharing options...
fry2010 Posted March 25, 2009 Share Posted March 25, 2009 excellent mate good job. To quote the message in a text box just a little hint... forget about the box and making the text smaller basically just forget about styling it for the moment. Try to get the quote message to output in plain text. Once you get that you can then start adding your styles to it. You will need to grab the message that is being quoted so will have to grab that from the database. Then simply echo it along with the reply message. Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793516 Share on other sites More sharing options...
rEhSi_123 Posted March 25, 2009 Author Share Posted March 25, 2009 excellent mate good job. To quote the message in a text box just a little hint... forget about the box and making the text smaller basically just forget about styling it for the moment. Try to get the quote message to output in plain text. Once you get that you can then start adding your styles to it. You will need to grab the message that is being quoted so will have to grab that from the database. Then simply echo it along with the reply message. No problem dude I will try this but all in all.... Thanks for all the support and guidiance...... Link to comment https://forums.phpfreaks.com/topic/150800-solved-phpmysql-help-please/page/2/#findComment-793519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.