undefined variable problem {solved}

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

undefined variable problem {solved}

Post 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;
    }
Last edited by scarface222 on Tue Jun 16, 2009 7:20 pm, edited 1 time in total.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: undefined variable problem

Post 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 '';
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: undefined variable problem

Post 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.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: undefined variable problem

Post by scarface222 »

i predefined as =""; lol and it worked before the while statement thanks bro
Post Reply