homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
My "FORM" is not displaying div
Scotty13




msg:4444030
 10:33 pm on Apr 22, 2012 (gmt 0)

When I test view_thread, I get this echo response from line 13 ERROR: That thread does not exist. DIV is at line 167-191 (marked)

<?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="javascript:parseResponse();" 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

 

Scotty13




msg:4444105
 6:20 am on Apr 23, 2012 (gmt 0)

FYI - The two database Tables for this Forum that I'm "trying" to build are up and running.

enigma1




msg:4444208
 12:14 pm on Apr 23, 2012 (gmt 0)

See if the thread is in the database by checking the ID after you get the error message.

if ($numRows < 1) {
echo sprintf('ERROR: Thread %s does not exist.', $thread_id);
exit();
}

rocknbil




msg:4444309
 3:52 pm on Apr 23, 2012 (gmt 0)

Well, your error trap is telling you what's wrong (which is good) - with that query, there's no results. Also you're quoting numeric values in your select which you shouldn't - this will alert you to what I suspect the problem is.

Per previous conversations - check your incoming value before trying to use it. Let's say "$thread_id" is null or empty. What does that give you?

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

A perfectly valid mySQL statement, but as you're finding out, it gives no results if something's wrong with your input. In a numeric field, there is no "empty". Without the quotes it would error and lead you right to the problem with a mysql error.

Your preg replace is fine - remove anything not a digit (but it's the long way around the fence.) So I'll bet $thread_id is now empty. Add something like this:

if (isset($_GET['id']) and is_numeric($_GET['id']) and ($_GET['id'] > 0)) {
// Since we've filtered it for numeric only, we can use it raw. Note there are NO QUOTES for this numeric field.
$sql = mysql_query("SELECT * FROM forum_posts WHERE id=".$_GET['id']." AND type='a' LIMIT 1") or die("Cannot execute query " . mysql_error());
// etc
}
else { echo "Oops! ID is not numeric id, thanks for playing! " . $_GET['id']); }

Scotty13




msg:4444401
 8:43 pm on Apr 23, 2012 (gmt 0)

Nothing seems to be working.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved