0

How do i fix Notice: Undefined index: topic_creator in C:\wamp\www\forum\view_category.php on line 313 Im getting two off this errors. I did read on a page that putting @ infront of $topic_creator may help, but i dident. I cant find a place that says how to fix it, so please help me. Here is my code

include_once("connect.php");
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1) {
    $sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
    $res2 = mysql_query($sql2) or die(mysql_error());
    if (mysql_num_rows($res2) > 0) {
    while ($row = mysql_fetch_assoc($res)) {

    **Line 313** if($row['topic_last_user']== "") { $last_user = getusername($row['topic_creator']); } else { $last_user = getusername($row['topic_creator']); }

        $topics .="
        <li class='category'><div class='left_cat'>
        <a class='underline' href='view_topic.php?cid=".$cid."&tid=".$tid."'>
        <div class='title'><i class='icon-comment'></i>&nbsp;".$title."</div></a>
        <div class='info'><i class='icon-comments icon-1'></i>&nbsp;".topicreplies($cid, $tid)." Comments&nbsp; &nbsp; &nbsp;<i class='icon-user icon-1'>
        &nbsp;</i>".$last2_user."&nbsp; ".$last_user."
Seb
  • 525
  • 1
  • 5
  • 25
  • You don't have key `topic_creator` in `$row`. `var_dump($row)` and see what keys you have there. – u_mulder Aug 31 '13 at 19:57
  • Oh this is what i have there `boolean false`.. @u_mulder – Seb Aug 31 '13 at 19:59
  • Also see http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php - your code is vulnerable to sql injection. And you should be careful using `@` in your code - it supresses errors, and make sure you really know what you're doing http://stackoverflow.com/questions/4872340/should-i-use-in-my-php-code – Raekye Aug 31 '13 at 20:00
  • 2
    I think you might have meant `$res2` in your while loop, not `$res`? (Naming variables more according to their actual purpose instead of such generic names helps avoid that kind of confusion.) – CBroe Aug 31 '13 at 20:01
  • Thank you @CBroe :) that was the problem $res2 not $res – Seb Aug 31 '13 at 20:03
  • Am marking this question as off-topic because solutions involving a misnamed variable are unlikely to be of widespread usefulness to Stack Overflow's usual audience. (Glad you fixed it though!). – halfer Aug 31 '13 at 20:21

0 Answers0