Jump to content

VanityCrush

Members
  • Posts

    41
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

VanityCrush's Achievements

Newbie

Newbie (1/5)

1

Reputation

  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
×
×
  • 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.