woodplease Posted September 7, 2010 Share Posted September 7, 2010 i'm trying to get the username of the last person to enter something into a database table,and display it an html table. the problem is, the query is failing, and i get the error "Table 'forum.posts' doesn't exist". if in the error message "forum" means the name of the database, and "posts" the name of the table, there is something wrong, as they both exist. the code i'm using is below $list = "SELECT * FROM section_main ORDER BY section_title"; $result = mysql_query($list) or die ("Query failed"); $numofrows = mysql_num_rows($result); for($j = 0; $j < $numofrows; $j++) { $row = mysql_fetch_array($result); echo "<tr><th>". $row['section_title']."</th></tr>"; $query2 = "SELECT * FROM section_sub WHERE section_id = '".$row['section_id']."' ORDER BY section_sub_title"; $result2 = mysql_query($query2) or die("Select Error :" . mysql_error()); $numofrows2 = mysql_num_rows($result2); for($i = 0; $i<$numofrows2; $i++){ $row2 = mysql_fetch_array($result2); echo "<tr><td><a href='display_forum.php?id={$row2[section_sub_id]}'>".stripslashes($row2[section_sub_title])."</a></td><td>"; $new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ") or die ("Select Error :" . mysql_error()); //this is where the error message is from $lastpost = mysql_fetch_assoc($new); echo $lastpost['username']; echo"</td></tr>"; } } i've checked that the names of the tables and fields in the queries are correct, but i cant think of anything else that might be wrong. any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/212805-getting-last-entry-in-database/ Share on other sites More sharing options...
objnoob Posted September 7, 2010 Share Posted September 7, 2010 Depending on the operating system... Capitalization of Table names is case-sensitive. http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html Also, Do all of your section_sub_id's have an extra space at the end of them? $new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ") should be $new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . "'") Quote Link to comment https://forums.phpfreaks.com/topic/212805-getting-last-entry-in-database/#findComment-1108456 Share on other sites More sharing options...
woodplease Posted September 7, 2010 Author Share Posted September 7, 2010 none of the table names are capitalized though Quote Link to comment https://forums.phpfreaks.com/topic/212805-getting-last-entry-in-database/#findComment-1108458 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 What method did you use to create this table? Have you successfully executed any queries using the posts table? If you cannot find the reason why mysql would report that the table does not exist, you would need to post your table definition so someone could look. You either have a spelling error, the actual table is in a different database, your have some non-printing characters as part of the table name (likely a space), or the table simply does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/212805-getting-last-entry-in-database/#findComment-1108462 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.