SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My DIV section is not displaying when I test in browser.

    When I test view_thread.php, I get this echo response from line 13 ERROR: That thread does not exist. DIV is at line 167-191 (marked). FYI - The two database Tables for this Forum that I'm "trying" to build are up and running.


    <?php
    session_start();
    include_once "../scripts/connect_to_mysql.php"; // Connect to the database
    // Connect to the class file for converting date_time to "Ago" format
    include_once ("../wi_class_files/agoTimeFormat.php");
    $myAgoObject = new convertToAgo; // Establish the object

    // Get the "id" URL variable and query the database for the original post of this thread
    $thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']);
    $sql = mysql_query("SELECT * FROM forum_posts WHERE id='$thread_id' AND type='a' LIMIT 1");
    $numRows = mysql_num_rows($sql);
    if ($numRows < 1) {
    echo "ERROR: That thread does not exist.";
    exit();
    }
    while($row = mysql_fetch_array($sql)){
    $post_author = $row["post_author"];
    $post_author_id = $row["post_author_id"];
    $date_time = $row["date_time"];
    $date_time = strftime("%b %d, %Y", strtotime($date_time));
    $section_title = $row["section_title"];
    $section_id = $row["section_id"];
    $thread_title = $row["thread_title"];
    $post_body = $row["post_body"];
    }
    ?>
    <?php
    // Now query any responses out of the database and place in a dynamic list
    $all_responses = "";
    $sql = mysql_query("SELECT * FROM forum_posts WHERE otid='$thread_id' AND type='b'");
    $numRows = mysql_num_rows($sql);
    if ($numRows < 1) {
    $all_responses = '<div id="none_yet_div">Nobody has responded to this yet, you can be the first.</div>';
    } else {
    while($row = mysql_fetch_array($sql)){
    $reply_author = $row["post_author"];
    $reply_author_id = $row["post_author_id"];
    $date_n_time = $row["date_time"];
    $convertedTime = ($myAgoObject -> convert_datetime($date_n_time));
    $whenReply = ($myAgoObject -> makeAgo($convertedTime));
    $reply_body = $row["post_body"];
    $all_responses .= '<div class="response_top_div">Re: ' . $thread_title . ' &nbsp; &nbsp; &bull; &nbsp; &nbsp; ' . $whenReply . '
    <a href="../res.php?id=' . $reply_author_id . '">' . $reply_author . '</a> Said/div>
    <div class="response_div">' . $reply_body . '</div>';
    }
    }
    ?>
    <?php
    // Be sure the user session vars are all set in order to show them the "replyButton"
    $replyButton = 'You must <a href="http://www.***********.com/ckin.php">CHECK IN</a> to respond';
    if (isset($_SESSION['id']) && isset($_SESSION['username']) && isset($_SESSION['useremail']) && isset($_SESSION['userloca'])) {
    $replyButton = '<input name="myBtn1" type="submit" value="Post a Response" style="font-size:16px; padding:12px;" onmousedown="javascript:toggleForm(\'reponse_form\');" />';
    }
    // Check the database to be sure that their ID, locator, and email session variables all match in the database
    $u_id = mysql_real_escape_string($_SESSION['id']);
    $u_name = mysql_real_escape_string($_SESSION['username']);
    $u_email = mysql_real_escape_string($_SESSION['useremail']);
    $u_loca = mysql_real_escape_string($_SESSION['userloca']);
    $sql = mysql_query("SELECT * FROM myMembers WHERE id='$u_id' AND username='$u_name' AND email='$u_email' AND locator='$u_loca'");
    $numRows = mysql_num_rows($sql);
    if ($numRows < 1) {
    $replyButton = 'You Must <a href="../ckin.php">CHECK IN</a> to Respond';
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.7.1.js" type="text/javascript"></script>
    <title><?php echo $thread_title; ?></title>
    <script language="javascript" type="text/javascript">
    function toggleForm(x) {
    if ($('#'+x).is(":hidden")) {
    $('#'+x).slideDown(200);
    } else {
    $('#'+x).slideUp(200);
    }
    }

    $('#responseForm').submit(function(){$('input[type=submit]', this).attr('disabled', 'disabled');});
    function parseResponse ( ) {
    var thread_id = $("#thread_id");
    var post_body = $("#post_body");
    var fs_id = $("#forum_section_id");
    var fs_title = $("#forum_section_title");
    var u_id = $("#tktedmembers_id");
    var u_loca = $("#tktedmembers_locator");

    var url = "parse_post.php";
    if (post_body.val() == "") {
    $("#formError").html('<font size="+2">Please type something</font>').show().fadeOut(3000);
    } else if (post_body.val().length < 2 ) {
    $("#formError").html('<font size="+2">Your post must be at least 2 characters long').show().fadeOut(3000);
    } else {
    $("#myBtn1").hide();
    $("#formProcessGif").show();
    $.post(url,{ post_type: "b", tid: thread_id.val(), post_body: post_body.val(), fsID: fs_id.val(), fsTitle: fs_title.val(), uid: u_id.val(), uloca: u_loca.val() } , function(data) {
    $("#none_yet_div").hide();
    var myDiv = document.getElementById('responses');
    var magicdiv1 = document.createElement('div');
    magicdiv1.setAttribute("class", "response_top_div");
    magicdiv1.htmlContent = 'Re: <?php echo $thread_title ?>';
    magicdiv1.innerHTML = 'Re: <?php echo $thread_title ?>';
    myDiv.appendChild(magicdiv1);
    var magicdiv = document.createElement('div');
    magicdiv.setAttribute("class", "response_div");
    magicdiv.htmlContent = data;
    magicdiv.innerHTML = data;
    myDiv.appendChild(magicdiv);
    $('#reponse_form').slideUp("fast");
    document.responseForm.post_body.value='';
    $("#formProcessGif").hide();
    $("#myBtn1").show();
    });
    }
    }
    </script>
    <style type="text/css">
    <!--
    .topic_div {
    background-color: #D9F9FF;
    font-size:16px;
    padding:16px;
    border: #01B3D8 1px solid;
    margin-bottom:6px;
    font-weight: 500;
    color:#069;
    }
    .response_top_div {
    background-color: #E4E4E4;
    color: #666;
    font-size:14px;
    padding:4px;
    border: #CCC 1px solid;
    border-bottom:none;
    color: #999;
    }
    .response_div {
    background-color: #FFF;
    font-size:14px;
    padding:12px;
    border:#CCC 1px solid;
    margin-bottom:6px;
    width:639px;
    overflow:hidden;
    }
    #none_yet_div {
    background-color: #E4E4E4;
    font-size:16px;
    padding:16px;
    border: #CCC 1px solid;
    margin-bottom:6px;
    color: #999;
    }
    -->
    </style>
    </head>
    <body>
    <?php include_once("template_header.php"); ?>
    <table style="background-color: #FFFFFF; border:#069 1px solid; border-top:none;" width="900" border="0" align="center" cellpadding="12" cellspacing="0">
    <tr>
    <td width="666" valign="top" style="line-height:1.5em;">
    <div id="breadcrumbs"><a href="http://www.***********.com/root/index.php">Return Home: My Global PNR</a> &larr; <a href="http://***********.com/root/forum/index.php">Return: Work & Trip Forum</a> &larr; <a href="section.php?id=<?php echo $section_id; ?>"><?php echo $section_title; ?></a></div>
    <br />
    <span class="topicTitles"><?php echo $thread_title; ?></span><br /><br />
    LINE 167: Topic Started by, TKTed Member: <a href="../res.php?id=<?php echo $post_author_id; ?>"><?php echo $post_author; ?></a>
    &nbsp; &nbsp; &nbsp; Created: <span class="topicCreationDate"><?php echo $date_time; ?></span>

    <div class="topic_div"><?php echo $post_body; ?></div>
    <div id="responses">
    <p>&nbsp;</p>
    <?php echo $all_responses; ?></div>

    <!-- START DIV that contains the form -->
    <div id="reponse_form" style="display:none; background-color: #BAE1FE; border:#06C 1px solid; padding:16px;">
    <form action="javascriptarseResponse();" name="responseForm" id="responseForm" method="post">
    Please type in your response here <?php echo $u_name; ?>br /><textarea name="post_body" id="post_body" cols="64" rows="12" style="width:98%;"></textarea>
    <div id="formError" style="display:none; padding:16px; color:#F00;"></div>
    <br /><br /><input name="myBtn1" id="myBtn1" type="submit" value="Submit Your Response" style="padding:6px;" /> <span id="formProcessGif" style="display:none;"><img src="../images/loading.gif" width="28" height="10" alt="Loading" vspace="2" hspace="48" /></span>
    or <a href="#" onclick="return false" onmousedown="javascript:toggleForm('reponse_form');">Cancel</a>
    <input name="thread_id" id="thread_id" type="hidden" value="<?php echo $thread_id; ?>" />
    <input name="forum_section_id" id="forum_section_id" type="hidden" value="<?php echo $section_id; ?>" />
    <input name="forum_section_title" id="forum_section_title" type="hidden" value="<?php echo $section_title; ?>" />
    <input name="tktedmembers_id" id="tktedmembers_id" type="hidden" value="<?php echo $_SESSION['id']; ?>" />
    <input name="tktedmembers_locator" id="tktedmembers_locator" type="hidden" value="<?php echo $_SESSION['userloca']; ?>" />
    </form>
    </div>
    <p>
    <!-- END DIV that contains the form -->
    LINE 191: <?php echo $replyButton; ?></p>
    <p>
    <br />
    <br />
    </p></td>
    <td width="184" valign="top"><div style=" width:160px; height:600px; background-color: #F0F0F0; color: #CCC; padding:12px;"> <br />
    <br />
    <br />
    <h3>Contact us to place your AD here.</h3>

    </div></td>
    </tr>
    </table>
    <?php include_once("template_footer.php"); ?>
    </body>
    </html>

    Thanks in advance, Scott

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Have you run the query to make sure it retrieves the information you think it should?

    (echo "SELECT * FROM forum_posts WHERE id='$thread_id' AND type='a' LIMIT 1")
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did and got...

    SELECT * FROM forum_posts WHERE id='' AND type='a' LIMIT 1

    ERROR: That thread does not exist.

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    I would guess there was somthing wrong with this line:
    PHP Code:
    $thread_id preg_replace('#[^0-9]#i'''$_GET['id']); 
    As long as the URL contained a vaue for id

    Why not start with a short piece of code just doing the basics as you should be able to find the problem easier.

  5. #5
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any suggestions?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    What are you putting on the URL for id?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •