Scotty13 Posted August 12, 2012 Report Share Posted August 12, 2012 (edited) Trying to build a forum. My two Tables that I built for this forum are good. When I test in my browsers… I click on a topic from my index.php It goes to section.php?id=36 (script below) If I click on my type="submit" value="Take Off With A Different Conversation" button. I get this “ERROR: You do not exist in the system.” from new_topic.php (script below). I’m following some tuts online and watched them over and over and its just not working, could you PLEASE HELP ME! Sorry for all the script, but I didnt want to leave anything out. ____________________________________________________________________________ section.php __________________________________________ <?php session_start(); include_once ("../wi_class_files/agoTimeFormat.php"); $myAgoObject = new convertToAgo; include_once "../scripts/connect_to_mysql.php"; // Connect to the database // Get the section ID from the url variable coming in if (isset($_GET['id']) && $_GET['id'] != "") { $sid = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter all characters except numbers for security } else { echo "ERROR: Variables to run this script have been removed from the URL."; exit(); } // Query the database for that section id, make sure it exists and get the section title $sql = mysql_query("SELECT * FROM forum_sections WHERE id='$sid' LIMIT 1"); $numRows = mysql_num_rows($sql); if ($numRows < 1) { echo "ERROR: That section does not exist you have tampered with our URLs."; exit(); } while($row = mysql_fetch_array($sql)){ $sectionTitle = $row["title"]; } // Use the section ID to query the "forum_posts" table in the database to get all the threads for this section $sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' AND section_id='$sid' ORDER BY date_time DESC LIMIT 25"); $dynamicList = ""; $numRows = mysql_num_rows($sql); if ($numRows < 1) { $dynamicList = "There are no threads in this section yet. You can be the first to post."; } else { while($row = mysql_fetch_array($sql)){ $thread_id = $row["id"]; $post_author = $row["post_author"]; $post_author_id = $row["post_author_id"]; $date_time = $row["date_time"]; $convertedTime = ($myAgoObject -> convert_datetime($date_time)); $whenPost = ($myAgoObject -> makeAgo($convertedTime)); $thread_title = $row["thread_title"]; $dynamicList .= '<img src="style/threadPic.jpg" width="26" height="18" alt="Topic" /> ' . $post_author . ' - <a href="view_thread.php?id=' . $thread_id . '">' . $thread_title . '</a> - ' . $whenPost . '<br />'; } } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style/style.css" rel="stylesheet" type="text/css" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <title><?php echo $sectionTitle; ?> Work & Trip Forum</title> <meta name="Keywords" content="Funny, work, coworker, work, today, wow, forum, airline, blog, announcing, announcer, announced, announce, blog, blogging, blogger, travel, tips, heard, tips, suggestions, nightmares, anniversary, retirement, birthday, party, heard, rumor, chat, gossip" /> </head> <body> <div align="center"> <?php include_once("template_header.php"); ?> </div> <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="731" valign="top"> <div id="breadcrumbs"><a href="http://www.**********.com">Return'>http://www.**********.com">Return Home: **********</a> ← <a href="http://************.com/root/forum/index.php">Return: Work & Trip Topics</a></div> <h1 style="margin-left:12px;"><?php echo $sectionTitle; ?> </h1> <form action="new_topic.php" method="post"> <input name="forum_id" type="hidden" value="<?php echo $sid; ?>" /> <input name="forum_title" type="hidden" value="<?php echo $sectionTitle; ?>" /> <input name="myBtn1" type="submit" value="Take Off With A Different Conversation" style="font-size:16px; padding:8px;" /> </form> <br /><br /> <div style="margin-left:12px; font-size:14px; line-height:1.5em;"><?php echo $dynamicList; ?></div> <br /><br /><br /></td> <td width="189" valign="top"><div style=" width:160px; height:600px; background-color: #F0F0F0; color: #CCC; padding:12px;"> <br /> <br /> _________________________________________________________________________________________ new_topic.php _____________________________________ <?php session_start(); include_once "../scripts/connect_to_mysql.php"; // Connect to the database // Check to see if the user is logged in with session variables if (!isset($_SESSION['userloca']) || $_SESSION['userloca'] == "") { echo "You'll need to check in first before you can post anything on your Work & Trip Forum."; exit(); } else { // Assume they are a tktedmembers because they have a locator session variable set // 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) { echo "ERROR: You do not exist in the system."; exit(); } } // Check to make sure the URL variables of "sid" and "title" are set if (!isset($_POST['forum_id']) || $_POST['forum_id'] == "" || !isset($_POST['forum_title']) || $_POST['forum_title'] == "") { echo "Important variables are missing"; exit(); } else { // Acquire the variables and proceed to show them a form for creating a new topic $forum_section_id = preg_replace('#[^0-9]#i', '', $_POST['forum_id']); $forum_section_title = preg_replace('#[^A-Za-z 0-9]#i', '', $_POST['forum_title']); } $sql = mysql_query("SELECT * FROM forum_sections WHERE id='$forum_section_id' AND title='$forum_section_title'"); $numRows = mysql_num_rows($sql); if ($numRows < 1) { echo "ERROR: That section does not exist."; exit(); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style/style.css" rel="stylesheet" type="text/css" /> <title><?php echo $sectionTitle; ?>Work & Trip Forum</title> <script type="text/javascript" language="javascript"> <!-- function validateMyForm ( ) { var isValid = true; if ( document.form1.post_title.value == "" ) { alert ( "Please type in a title for this topic" ); isValid = false; } else if ( document.form1.post_title.value.length < 10 ) { alert ( "Your title must be at least 10 characters long" ); isValid = false; } else if ( document.form1.post_body.value == "" ) { alert ( "Please type in your topic body." ); isValid = false; } return isValid; } //--> </script> </head> <body> <?php include_once("template_header.php"); ?> <table style="background-color: #F0F0F0; border:#069 1px solid; border-top:none;" width="900" border="0" align="center" cellpadding="12" cellspacing="0"> <tr> <td width="666" valign="top"> <div id="breadcrumbs"><a href="http://www.**********.com">Return Home: **********</a> ← <a href="http://***********.com/root/forum/index.php">Return: Work & Trip Forum</a> ← <a href="section.php?id=<?php echo $forum_section_id; ?>"><?php echo $forum_section_title; ?></a></div> <h2>Creating a new topic in the <em><?php echo $forum_section_title; ?></em>Work & Trip Form</h2> <form action="parse_post.php" method="post" name="form1"> <input name="post_type" type="hidden" value="a" /> Announcer:<br /><input name="topic_author" type="text" disabled="disabled" maxlength="64" style="width:96%;" value="<?php echo $u_name; ?>" /> <br /><br /> Announcement Title:<br /><input name="post_title" type="text" maxlength="64" style="width:96%;" /><br /><br /> Tell Us What Happen Today... <span class="smtext"> (Use only fictitious names if describing a passenger) </span><br /> <br /> Please type in your topic body:<br /><textarea name="post_body" rows="15" style="width:96%;"></textarea> <br /><br /><input name="" type="submit" value="Post Announcement!" onclick="javascript:return validateMyForm();"/> <input name="fsID" type="hidden" value="<?php echo $forum_section_id; ?>" /> <input name="fsTitle" type="hidden" value="<?php echo $forum_section_title; ?>" /> <input name="uid" type="hidden" value="<?php echo $_SESSION['id']; ?>" /> <input name="uloca" type="hidden" value="<?php echo $_SESSION['userloca']; ?>" /> </form> ________________________________________________________________________________________________________________________________________________ Scotty13 Edited August 12, 2012 by Scotty13 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 12, 2012 Report Share Posted August 12, 2012 Your issue lies with these lines: $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) { echo "ERROR: You do not exist in the system."; exit(); } Specifically, the query you are using isn't matching with the active user. I would start by displaying $u_id, $u_name, $u_email and $u_loca in your browser, to ensure they are being set properly. For example, add this right before the SQL query: echo "id: " . $u_id . '<br>'; echo "name: " . $u_name . '<br>'; echo "email: " . $u_email . '<br>'; echo "loca: " . $u_loca . '<br>'; exit; If that works fine, and your various variables are correct, then I'd suggest plugging your query into PHPMyAdmin, replacing the variables with your data, and seeing if maybe theres some sort of error in the syntax. Maybe a misspelling? Something that should be capitalized that isn't? My guess is that one of the variables isn't being set correctly though. Quote Link to comment Share on other sites More sharing options...
Scotty13 Posted August 12, 2012 Author Report Share Posted August 12, 2012 Your issue lies with these lines: $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) { echo "ERROR: You do not exist in the system."; exit(); } Specifically, the query you are using isn't matching with the active user. I would start by displaying $u_id, $u_name, $u_email and $u_loca in your browser, to ensure they are being set properly. For example, add this right before the SQL query: echo "id: " . $u_id . '<br>'; echo "name: " . $u_name . '<br>'; echo "email: " . $u_email . '<br>'; echo "loca: " . $u_loca . '<br>'; exit; If that works fine, and your various variables are correct, then I'd suggest plugging your query into PHPMyAdmin, replacing the variables with your data, and seeing if maybe theres some sort of error in the syntax. Maybe a misspelling? Something that should be capitalized that isn't? My guess is that one of the variables isn't being set correctly though. Quote Link to comment Share on other sites More sharing options...
Scotty13 Posted August 12, 2012 Author Report Share Posted August 12, 2012 I added a screen shot of my two tables, forum_posts and forum_sections. maybe I'm missing something in my tables, which both test 100%. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 12, 2012 Report Share Posted August 12, 2012 This line: mysql_query("SELECT * FROM myMembers WHERE id='$u_id' AND username='$u_name' AND email='$u_email' AND locator='$u_loca'"); refers to a "myMembers" table? It has nothing to do with the forum topics or sections. Quote Link to comment Share on other sites More sharing options...
Scotty13 Posted August 12, 2012 Author Report Share Posted August 12, 2012 Sorry, new to all this. So I need to add to myMembers table is u_id, u_name, u_email AND u_loca? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 13, 2012 Report Share Posted August 13, 2012 According to your query, you need to have a "myMembers" table that includes columns for "id", "username", "email" and "locator". I can't say much more than that -- I'm assuming you are getting this code from somewhere, so you'll have to reference whatever sample code or tutorial you are following. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.