Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Can't get ID

Asked Modified Viewed 911 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

@RobiNN
I know that you are incredibly busy RobiNN and that you get frustrated with some of my peculiar coding habits but maybe you can easily see what I am doing wrong here. This is concerning my home-grown blog system. I can delete a comment but then can't update the POSTS table to reduce the comment count by one. Here is my code snippet:
if (isset($_POST['delete'])) {
   $result = dbquery("DELETE FROM ".DB_GRIMS_BLOG_COMMENTS." WHERE comment_id='".$_POST['comment_id']."'");
   $result1 = dbquery("UPDATE ".DB_GRIMS_BLOG_POST." SET comments=comments-1 WHERE post_id ='".$_GET['my_id']."'");

   echo "<table align='center' width='100%' border='0' class='mytable'><tr>n";
   echo "<td align='center'><b>".$locale['gb_131']."</b></td>n";
   echo "</tr></table>n";
exit();
}
// Select comment to edit
   echo "<div style='text-align:center'><h5><b>Select A Comment To Edit Or Delete</b></h5><br /><br /></div>n";
   $editlist = ""; $sel = "";
   $result = dbquery("SELECT * FROM ".DB_GRIMS_BLOG_COMMENTS." ORDER BY comment_id DESC");
   if (dbrows($result) != 0) {
      while ($data = dbarray($result)) {
      $result1 = dbquery("SELECT post_id, post_title FROM ".DB_GRIMS_BLOG_POST." WHERE post_id='".$data['post_id']."'");
         while ($stuff = dbarray($result1)) {
         $my_id = $stuff['post_id'];
         $post = $stuff['post_title'];
         }
    if (isset($_POST['comment_id']) && isnum($_POST['comment_id'])) {
          $sel = ($_POST['comment_id'] == $data['comment_id'] ? " selected" : "");
         }
         $editlist .= "<option value='".$data['comment_id']."'$sel>".$data['name']." - $post - $my_id</option>n";
      }
   echo "<div style='text-align:center'>n";
   echo "<form id='edit_select' name='edit_select' method='post' action='".FUSION_SELF."'>n";
   echo "<b>Comment: </b><select id='comment_id' name='comment_id' class='textbox' style='width:350px;'>".$editlist."</select>n";
   echo "<input class='button' type='submit' name='edit' value='".$locale['gb_161']."' />n";
   echo "</form><br /><br />n";
   echo "</div>n";
}

The editlist properly shows the Comment Poster($data['name']), the Post Title($post) and the Post Id($my_id) but then after the DELETE query is executed(which does deletes the comment) the second query to reduce the comment field by one in the POSTS table does not work. I know this is rather cryptic but it's the best way I can explain it. Neither $_GET nor $_POST seems to work. Hoping for a clue here. Thanks in advance.
0 replies

1 post

D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

The second query is looking for the ID in the table DB_GRIMS_BLOG_POST via $_GET['my_id'], but the form is submitted via POST.
I can not find a variable my_id submitted via GET.

Best option is to get the post_in the DB_GRIMS_BLOG_POST lookup via a query via DB_GRIMS_BLOG_COMMENTS, (will costs you an extra query)
It will be hard to extract it from the <select> value I am afraid

Or make a hidden field in the form and put the post_id somewhere in there
1 reply

Labels

Statistics

  • Views 0 views
  • Posts 1 post
  • Votes 0 votes
  • Topic users 2 members

2 participants

G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet