Forum Moderators: coopster
I'm new here, but I'm wondering if you could help me please.
Basically I am create a forum in PHP and would like to have a search feature.
However
I am having some problems
my code is:
$getuser = mysql_query("SELECT * from $pretopics where author LIKE '$_GET[membername]'");
while ($results = mysql_fetch_array($getuser))
{
echo("
<tr>
<td width=\"20%\">
$results[topic_name]
</td>
<td width=\"10\">
$results[author]
</td>
<td width=\"10%\">
$results[forum_id]
</td>
<td width=\"50%\">
</td>
</tr>");
}
however that works fine ... but I need it so it always gets data from the table: $preposts
Your help in assisting me would be gratefully appreciated.
Thanks
Andy
$getuser = mysql_query("SELECT * from $pretopics where author LIKE '$_GET[membername]'");
Off topic. The above line is an invitation to security problems.
NEVER use unsanitized user generated data in a query.
Imagine $_GET[membername] = hi'OR 1=1
We have just completed the first step towards compromising your entire application.
Do a search on sql injection.
About your original question, I am not sure I understand it. On the surface, it appears that substituting $preposts for $pretopics in your query would solve the problem, but I suspect you are asking something different than that.
WBF
Sounds like you need to either use a JOIN query statement or run another query to retrieve your posted data from the other table. I just posted some JOIN links the other day for somebody else, here they are ...
[webmasterworld.com...]
And here is a starter on that SQL Injection [php.net] mentioned. The PHP Forum Library [webmasterworld.com] also has some security tips in regards to the topic.
Column 'author' in where clause is ambiguous
I am getting that with the join the code:
$getuser = mysql_query("SELECT $preposts.*, $pretopics.* FROM $preposts LEFT JOIN $pretopics ON ($preposts.author = $pretopics.author) WHERE author = '$_GET[membername]'") or die(mysql_error());
Probably all wrong though :O
Can you help please?
Thanks
And pay attention to the comment on sanitizing user input!
Here's some info:
[php.net...]