Jump to content

VanityCrush

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by VanityCrush

  1. You could try including the init.php file in your settings.php file like so: require_once('../../template/header.php'); require_once('../../core/init.php'); And remove the call from the header.php file. Any reason why you're calling the init.php file from header.php? Or you can just have everything in your init.php file (the db connection, functions, and templates) which you can then include in your files. /home /core /init.php /dbcon /connection.php in your init.php file require('dbcon/db_connection.php'); require('../template/header.php'); in your setings.php file include('../../core/init.php');
  2. Try this.. require_once '../../template/header.php'; I don't think you can use the $dir variable here because it will always point to the /members/private/ path, while you need to go back two directories. The code written before works for me, having the same structure as you. But I am including it in an index.php file located in the /home dir so maybe that's why it didn't work for you..
  3. Can't edit my previous answer, sorry for the double post. You could try: settings.php file require_once('template/header.php'); index.php file include('members/private/settings.php'); If you're calling it from the home/ dir With the $dir variable it would look like this: settings.php require_once($dir.'/template/header.php'); index.php file include($dir.'/members/private/settings.php'); You can drop the parenthesis, I just like to put them there.
  4. Can you not just use require_once 'template/header.php'; Also, where is the file calling this located? If it's in home/ it should work
  5. Ah, I understand now. Thank you both ! I can't help but wonder though. Am I returning the create_blog_captcha() value correctly doing this? It works, but it seems a bit awkward $captchanum = $num1 . ' + ' . $num2 . ' = '; $captchanum .= '<input type="text" name="captcha_results" size="2"> <input type="hidden" name=\'num1\' value=' . $num1 . '> <input type="hidden" name=\'num2\' value=' . $num2 . '>'; return $captchanum;
  6. You mean something like this? function comment_form($id, $captcha) { global $user_data; if (logged_in() === true) { return <<<EOT <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name' value='{$user_data['username']}'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name='blog_id' value='$id'> <input type='submit' name='submit' id='post' value='post'> </form> <hr class='artline'> EOT; } } function list_articles($rows) { if(empty($rows)){ return "There are no Articles to display"; } $create_blog_captcha = create_blog_captcha(); $previous_blog_id = 0; $content = ''; foreach($rows as $row) { if ($previous_blog_id != $row['content_id']) { // the blog id changed if($previous_blog_id != 0) { // not the first section, close out the previous section $content .= comment_form($previous_blog_id, $create_blog_captcha); } // start a new blog section $content .= "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { $content .= "<div class='commented_by'>User: {$row['comment_by']} </div> <div class='comments'>Comment: {$row['comments']}</div> <hr class='artline2'>"; } } if($previous_blog_id != 0){ $content .= comment_form($previous_blog_id, $create_blog_captcha); } return $content; } function create_blog_captcha() { $num1 = generate_captcha(1, 20); $num2 = generate_captcha(1, 20); $captchanum = $num1 . ' + ' . $num2 . ' = '; $captchanum .= '<input type="text" name="captcha_results" size="2"> <input type="hidden" name=\'num1\' value=' . $num1 . '> <input type="hidden" name=\'num2\' value=' . $num2 . '>'; return $captchanum; } I don't get a captcha box returned. Am I doing it completely wrong?
  7. It seems that it has to do with the fact that I'm echoing the comment forms instead of returning the results like so function comment_form($id) { global $user_data; if (logged_in() === true) { return <<<EOT <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name' value='{$user_data['username']}'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name='blog_id' value='$id'> <input type='submit' name='submit' id='post' value='post'> </form> <hr class='artline'> EOT; However, I cannot insert a function because of the <<<EOT I had to use. How can I insert the create_captcha function into the above? Is it even possible?
  8. As you may know by now... I have some functions that generate the articles on my page + the comments associated with them (thanks to Barand and mac_gyver) function comment_form($id) { // generates a comment box form for every article on the page global $user_data; if (logged_in() === true) { echo " <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name' value='{$user_data['username']}'> <div class='captcha'>" . create_captcha() . "</div> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name='blog_id' value='$id'> <input type='submit' name='submit' id='post' value='post'> </form> <hr class='artline'>"; } } function list_articles($rows) { if(empty($rows)){ return "There are no Articles to display"; } $previous_blog_id = 0; $content = ''; foreach($rows as $row) { if ($previous_blog_id != $row['content_id']) { // the blog id changed if($previous_blog_id != 0) { // not the first section, close out the previous section $content .= comment_form($previous_blog_id); } // start a new blog section $content .= "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { $content .= "<div class='commented_by'>User: {$row['comment_by']} </div> <div class='comments'>Comment: {$row['comments']}</div> <hr class='artline2'>"; } } if($previous_blog_id != 0){ $content .= comment_form($previous_blog_id); } return $content; } function insert_comments($comments, $comment_by, $blog_id) { include('core/db/db_connection.php'); $comment_by = sanitize($comment_by); $comments = sanitize($comments); $blog_id = (int)$blog_id; $sql = "INSERT INTO article_comments (comments, comment_by, blog_id) VALUES ('$comments', '$comment_by', '$blog_id')"; mysqli_query($dbCon, $sql); } I generate a simple math captcha like per below: function generate_captcha($num1, $num2) { // generates 2 random numbers $num1 = (int)$num1; $num2 = (int)$num2; $rand_num_1 = mt_rand($num1, $num2); $rand_num_2 = mt_rand($num1, $num2); $result = $rand_num_1 + $rand_num_2; return $result; } function create_captcha() { // displays captcha on the page $num1 = generate_captcha(1, 20); $num2 = generate_captcha(1, 20); echo $num1 . ' + ' . $num2 . ' = '; echo '<input type="text" name="captcha_results" size="2">'; echo '<input type="hidden" name=\'num1\' value=' . $num1 . '; ?>'; echo '<input type="hidden" name=\'num2\' value=' . $num2 . '; ?>'; } As you can see, I'm using the create_captcha() function into my comment_form() function because I want every comment box to have a captcha associated with it. The same way every article has it's own comment box. The above code is displaying a captcha field for each comment box I have, which is what I want. However - it moves all the comment boxes above the content making it look something like this: |-------------------------------------| // comments form for article 1 |Name: New User | |Comment: New comment ! | | | |-------------------------------------| [Submit] [captcha field] |-------------------------------------| // comments form for article 2 |Name: New User | |Comment: New comment ! | | | |-------------------------------------| [Submit] [captcha field] ========================================================== Article_1 title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- //comments Name: User0 Comment: Great article! -------------------------------------- Name: User1 Comment: Great article! - 2nd comment -------------------------------------- // end comments ============================================================ Article_2 title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- //comments Name: User0 Comment: Great article! -------------------------------------- Name: User1 Comment: Great article! - 2nd comment -------------------------------------- // end comments The behavior I am expecting is this: Article_1 title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- //comments Name: User0 Comment: Great article! -------------------------------------- Name: User1 Comment: Great article! - 2nd comment -------------------------------------- // end comments |-------------------------------------| // comments form for article 1 |Name: New User | |Comment: New comment ! | | | |-------------------------------------| [Submit] [captcha field] ============================================================ Article_2 title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- //comments Name: User0 Comment: Great article! -------------------------------------- Name: User1 Comment: Great article! - 2nd comment -------------------------------------- // end comments |-------------------------------------| // comments form for article 2 |Name: New User | |Comment: New comment ! | | | |-------------------------------------| [Submit] [captcha field] Is it something to do with the position in which I'm inserting the generate_captcha function that causes the comment boxes to float above content? I figured that in order to execute the captcha function I must insert in into the one that generates the comment form for the articles. Thank you.
  9. @mac_gyver Ok, so I fixed it - however the behavior is not the one I'm expecting. I have 3 articles with the id of 1, 11, and 12. Each article has now it's own comment form. If I comment on article 1, all good, the comment gets inserted with the correct blog_id_[fk] and displayed on the page. However, If I comment on article 11, the comment goes to article 1. When I comment on article 12, the comment goes to article 11. The comment form seems to be 1 article behind... any clue?
  10. @mac_gyver Thanks for the effort in trying to put this together. I've tried to wrap my mind around that.. There seems to be an issue with this part of the code: function list_articles($rows) { // if(empty($rows)){ // return "There are no Blogs to display"; // } $previous_blog_id = 0; $content = ''; foreach($rows as $row){ The rows always return empty. If I comment them out to try and execute the other part of the code - the following error occurs: Warning: Invalid argument supplied for foreach() this must be because the $rows variable is null, and I don't understand why.. Note that I am calling the echo from another page, and I'm doing it like so: <?php echo list_articles(get_articles($dbCon)); if (!empty($_POST)) { insert_comments($_POST['comments'], $_POST['username'], $_POST['blog_id']); } ?> @Barand I have tried implementing the above like so: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by, article_comments.comment_id FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); $previous_blog_id = 0; while ($row = mysqli_fetch_array($result)) { $saved_comment_id = $row['comment_id']; if ($previous_blog_id != $row['content_id']) { echo "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'> <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name='blog_id' value='$saved_comment_id'> <input type='submit' id='post' value='post'> </form>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { echo "<div class='commented_by'>Posted by: {$row['comment_by']} </div> <div class='comments'>Comment: {$row['comments']}</div> <hr class='artline2'>"; } } } function insert_comments($comments, $comment_by, $blog_id) { include('core/db/db_connection.php'); $comment_by = sanitize($comment_by); $comments = sanitize($comments); $sql = "INSERT INTO article_comments (comments, comment_by, blog_id) VALUES ('$comments', '$comment_by', '$blog_id')"; mysqli_query($dbCon, $sql); } And this is how I'm calling the functions: <?php echo list_articles(); if (!empty($_POST)) { insert_comments($_POST['comments'], $_POST['username'], $_POST['blog_id']); } ?> All works well, no errors, comments are displaying, forms are displaying.. However, I am only able to add comments (through the forms) only for article 1. I submit the form, and the comment gets submitted in the database correctly and gets displayed on the page. If I try to do the same thing for article 2, the form submission will not work, nothing gets inserted in the database. I have to assume that the variable I'm using $saved_comment_id is always 1? Even if so, comments should still be posting to article 1... I'm using error_reporting(E_ALL); ini_set('display_errors', '1'); but I get no errors.
  11. Sounds like you're gonna need Ajax to accomplish the zooming,grabbing and moving, etc. Making the map to fit on the user's monitor can be accomplished setting a width in percentages (max-width/min-width) while detecting the window size using JavaScript to adjust it accordingly for any screen resolution. Unless I'm misunderstanding your question. Is the map you're using a google maps api by any chance? You could also check this out if that's the case: google_maps
  12. Thanks, however I don't think the $sql2 is the correct approach. Code works fine now, but I'm back to square 1. For each comment inserted articles get duplicated. <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name=blog_id' value='{$row['blog_id']}'> <input type='submit' name='submit' id='post' value='post'> </form>"; is there any way to target the blog_id without calling while ($row = mysqli_fetch_array($result)) {} ? or at least, not calling it in the second while loop? With the first piece of code I posted I get the following results: Article title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- Name: DSK Comment: Great article! -------------------------------------- Name: DSK Comment: Great article! - 2nd comment -- BEGIN SECOND ARTICLE ON WEBPAGE Article title: LOREM IPSUM 2nd article Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- Name: User0 Comment: Great article! -------------------------------------- Name: User1 Comment: Great article! - 2nd comment -------------------------------------- Name: User2 Comment: Great article! - 3rd comment -------------------------------------- Which is exactly what I'm looking for. However I can only insert comments via the phpmyadmin interface, manually selecting the foreign key(blog_id). I would like to be able to get the same results through a form: Article title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- //comments Name: DSK Comment: Great article! -------------------------------------- Name: DSK Comment: Great article! - 2nd comment -------------------------------------- // end comments |-------------------------------------| // comments form |Name: New User | |Comment: New comment ! | | | |-------------------------------------| [Submit] When the user submits the form, his name and his comment gets submitted to the database into article_comments table. Also the foreign key (blog_id) should link to an existing article (which it does). I just need a way to target this blog_id in my function so I can use it as a param. God, I'm so lost. Does that make any sense?....
  13. I've tried to display it in the same way as I'm displaying the articles, however I get an undefined index error for blog_id when I try to target it with $row['blog_id'] Therefore I have tried the below: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); $previous_blog_id = 0; while ($row = mysqli_fetch_array($result)) { if ($previous_blog_id != $row['content_id']) { echo "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { echo "<div class='commented_by'>Posted by: {$row['comment_by']} </div> <div class='comments'>Comment: {$row['comments']}</div> <hr class='artline2'>"; } $sql2 = "SELECT blog.content, article_comments.blog_id FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != ''" $result2 = mysqli_query($dbCon, $sql2); while ($row = mysqli_fetch_array($result2)) { echo " <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name=blog_id' value='{$row['blog_id']}'> <input type='submit' name='submit' id='post' value='post'> </form>"; } } } This doesn't seem to do the trick as I get syntax error, unexpected '$result2' (T_VARIABLE) I've modiefied the second sql query to: $sql2 = "SELECT FROM article_comments VALUES blog_id"; $result2 = mysqli_query($dbCon, $sql2); while ($row = mysqli_fetch_assoc($result2)) { echo " <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name=blog_id' value='{$row['blog_id']}'> <input type='submit' name='submit' id='post' value='post'> </form>"; } mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given - is the error i get in doing so. I do need the value of blog_id to be boolean though... Tell me if what I'm doing doesn't make any sense, not sure it does either. I'm new to all this stuff. Trying to learn on the fly..
  14. I am only outputting 1 comment form at the bottom of the page so far. I understand how the hidden form field could work: something like this maybe <input type="hidden" name="blog_id" value="11"> However, I do not want to manually insert the blog_id value, I want this to be automatically picked up from the database table. Once the value is picked up, the comments will point to the article they correspond. I'm not sure how can I accomplish that.. Here is what I'm thinking: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); $previous_blog_id = 0; while ($row = mysqli_fetch_array($result)) { if ($previous_blog_id != $row['content_id']) { echo "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'> <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='hidden' name='blog_id' value='{$row['blog_id']}'> <input type='submit' name='submit' id='post' value='post'> </form>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { echo "<div class='commented_by'>Posted by: {$row['comment_by']} </div> <div class='comments'>Comment: {$row['comments']}</div> <hr class='artline2'>"; } } } That's displaying a comment form for each article, but it doesn't seem to pick the value of the blog_id field
  15. Me again.. I've struggled for the past 2 hours to insert article comments and link them to an existent article on the page. Now, the function that is displaying both comments and articles looks like this: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); $previous_blog_id = 0; while ($row = mysqli_fetch_array($result)) { if ($previous_blog_id != $row['content_id']) { echo "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { echo "<div class='commented_by'>Posted by: {$row['comment_by']} </div> <div class='comments'>Comments: {$row['comments']}</div> <hr class='artline2'>"; } } } The function I'm running to insert comments into article_comments table function insert_comments($comments, $comment_by, $blog_id) { include('core/db/db_connection.php'); $comment_by = sanitize($comment_by); $comments = sanitize($comments); $sql = "INSERT INTO article_comments (comments, comment_by, blog_id) VALUES ('$comments', '$comment_by', '$blog_id')"; mysqli_query($dbCon, $sql); } This works - it does the insertion, however I have no clue on how I could target the $blog_id variable when the user submits the post... The below is the form I use <?php echo list_articles(); if (!empty($_POST)) { insert_comments($_POST['comments'], $_POST['username'], 11); } ?> <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='submit' name='submit' id='post' value='post'> </form> I bet you noticed that I've manually inserted 11 as a param for the last variable. This links to blog_id 11 (the foreign key) in my article_comments table. It is displaying the comment just fine. Is there any way to target $blog_id without having to insert a number manually? Something like how I am targeting the $comments variable using $_POST['comments'] ? Also, even if I can target that, how do I know which post is the user commenting to? Should I give them the option to choose in a drop-down list ? That seems awkward.. but it's the only solution I can think of.
  16. Hi Barand, thank you once more for trying to help me out. Please see below the issues I get with ON blog.content_id = article_comments.blog_id Results on the web page: Article title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- Name: DSK Comment: Great article! -- HERE IT DUPLICATES THE ARTICLE TO DISPLAY A NEWLY INSERTED COMMENT -- Article title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- Name: DSK Comment: Great article! - 2nd comment As you can see, it duplicates the article for every comment inserted. So I end up with two duplicate articles that hold different comments. If If I'll have 100 comments, the article will get replicated 100 times The behavior I am expecting: Article title: LOREM IPSUM Content: LOREM IPSUM DOLOR SIT AMET.... -------------------------------------- \\ COMMENTS \\ Name: DSK Comment: Great article! -------------------------------------- Name: DSK Comment: Great article! - 2nd comment Does this help clarify what I'm trying to accomplish ?
  17. So, I have modified my code and it now looks like this: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.content_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); while ($row = mysqli_fetch_array($result)) { echo "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" . "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" . "<article>" . $content = $row['content'] . "</article>" . "<div class='commented_by'>Posted by: " . $row['comment_by'] . "</div>" . "<div class='comments'>Comments: " . $row['comments'] . "</div>"; } } And this is how I'm now inserting comments in the database: function insert_comments($comment_by, $comments) { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, article_comments.blog_id FROM blog AS blog INNER JOIN article_comments AS article_comments ON article_comments.blog_id > blog.content_id"; mysqli_query($dbCon, $sql); } IN PHPMyAdmin the foreign key works alright and the comments are linked to a specific article. I want to transpose this on a web page. When I insert a new article on the page it works alright, but when I try to insert a comment for that article it will not display it. If I change ON blog.content_id = article_comments.content_id to ON blog.content_id = article_comments.blog_id (blog_id is the field name for the foreign key) - it will display all the comments for an article - but it duplicates that article for each comment associated with it. I'm not looking for someone to actually go ahead and give me the code, I just want to be pointed in the right direction as I feel a bit lost and I would appreciate some help. EDIT: Just to clarify - For now, I am inserting data directly through the database interface until I figure out how to display it properly, hence no INSERT statement in my code. So, my problem lays in displaying it. In the database, comments are associated with articles correctly. The way I display them on the page seems to be the issue. More than likely there's an issue with the way I am selecting either the comments or the articles.
  18. Duh, nope.. all values were set automatically to 0 while the content_id on the blog table was auto incremented to 8. I have changed these to match and everything works ok now. Thanks for all your help. I'll go test how I can implement this in a new query now
  19. I have tried creating a foreign key: ALTER TABLE article_comments ADD CONSTRAINT comment_blog_fk FOREIGN KEY (blog_id) REFERENCES wt.blog(content_id) ON DELETE NO ACTION ON UPDATE CASCADE; but I get the error #1452 - Cannot add or update a child row: a foreign key constraint fails (worldtour.#sql-22a4_47b, CONSTRAINT comment_blog_fk FOREIGN KEY (blog_id) REFERENCES blog (content_id) ON DELETE NO ACTION ON UPDATE CASCADE). Any idea why?
  20. Thanks for the suggestion regarding the connection, I'll update my code. No, I have tried using UPDATE but every time I insert a new comment it deletes the previous one. I would like to be able to store comments and display them uniquely for each article they are linked to. I was thinking of creating a foreign key in table A and link it with table B. I'll do some reading on it and get back with my results.
  21. Sorry, I should have also posted the code that's trying to insert the comments in the database. This is where I want to check if column_id A is = with column_id B. Before I try what you suggested, can you please let me know what's wrong with my code? function insert_comments($comment_by, $comments) { include('core/db/db_connection.php'); $sql = "INSERT INTO article_comments (comments, comment_by) VALUES ('$comments', '$comment_by') WHERE article_comments.comment_id = blog.content_id"; mysqli_query($dbCon, $sql); } EDIT: Does this look ok? How can I use the below to actually insert the comments in my database now? function insert_comments($comment_by, $comments) { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, article_comments.comment_id FROM blog AS blog INNER JOIN article_comments AS article_comments ON article_comments.comment_id > blog.content_id"; mysqli_query($dbCon, $sql); }
  22. Is it possible to link column_id from table A with column_id from table B? For example: If column_id A has a value of 6, column_id B should not be able allow entries if the column_id B is more than the value of column id A. I am running the below function to extract data from these tables: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.comment_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); while ($row = mysqli_fetch_array($result)) { echo "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" . "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" . "<article>" . $content = $row['content'] . "</article>" . "<hr class='artline'>" . "<div class='commented_by'>" . $row['comment_by'] . "</div>" . "<div class='comments'>" . $row['comments'] . "</div>"; } } Thanks.
  23. I've tried to add a hidden field but I still can't get rid of the captcha 'empty field' error. I think my approach is just wrong, any suggestions on how I can improve it?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.