Page is a not externally linkable
rocknbil - 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']); }