Page 1 of 1

undefined variable problem {solved}

Posted: Tue Jun 16, 2009 3:39 pm
by scarface222
hey guys this is my code and i get the message Notice: Undefined variable: result in C:\Web Files\wamp\www\***\***.php on line 60 which is the highlighted line. Any ideas? I thought the variable is defined.

Code: Select all

if(!$_POST['action']){
    
    header ("Location: index.html"); 
}
else{
    $link = connect(HOST, USER, PASSWORD);
    switch($_POST['action']){
        case "update":
            $res = getContent($link, 20);
            while($row = mysql_fetch_array($res)){
                [color=#FF0000]$result .= "<li><strong>".$row['user']."</strong><img src=\"css/images/bullet.gif\" alt=\"-\" [/color]/>".$row['message']." <span class=\"date\">".$row['date']."</span></li>";
            }
            echo $result;
            break;
        case "insert":
            echo insertMessage($_POST['nick'], $_POST['message']);
            break;
    }

Re: undefined variable problem

Posted: Tue Jun 16, 2009 4:42 pm
by Mark Baker
$result .= "<li>..."
is concatenating "<li>..." to the existing value of $result, except that $result doesn't yet exist.

Try predefining $result as '';

Re: undefined variable problem

Posted: Tue Jun 16, 2009 7:08 pm
by scarface222
Thanks for the reply bro but I don't quite understand what you are saying. $result=";? Could you explain more sorry I am kind of an amateur sometimes.

Re: undefined variable problem

Posted: Tue Jun 16, 2009 7:19 pm
by scarface222
i predefined as =""; lol and it worked before the while statement thanks bro