PHP Chat Problems

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
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

PHP Chat Problems

Post by like_duh44 »

Hello, I am making a web chat for my website and have the following script to get info from the mysql database. For Some reason, it says
[] operator not supported for strings
but it isnt a string, its an array, as you can see in the second part, they're exactly the same, even the tables in the database are the same, but for some reason, its not letting me get the info. Please help. Thanks

Code: Select all

<?php
echo "<meta http-equiv="Refresh" content="5">";
$name = $_GET&#1111;username];


    $server = "not shown for security reasons";
    $database = "not shown for security reasons";
    $user = "not shown for security reasons";
    $password = "not shown for security reasons";
    $def = "1";

    $link = mysql_connect($server, $user, $password)
        or die("Could not connect");
    mysql_select_db($database, $link) or die("Could not select database");

    $query = "SELECT * FROM chat_users WHERE def=$def";
    $result = mysql_query($query, $link) or die("Query failed Number 1");

    while ($row2 = mysql_fetch_row($result))
    &#123;
        $user&#1111;]=$row2;
    &#125;

    mysql_free_result($result);
    

echo "<table border="1"><tr>Welcome to the =AATA= Web Chat $name!<tr><td width="100"><b>Users Online:</b><br/>";

foreach ($user as $poster)
&#123;
$username = $poster&#1111;0];
echo "- $username<br/>";
&#125;

echo "</td><td width="500">";

    $query = "SELECT * FROM chat_posts WHERE def=$def";
    $result = mysql_query($query, $link) or die("Query failed Number 2");

    while ($row3 = mysql_fetch_row($result))
    &#123;
        $posts&#1111;]=$row3;
    &#125;

    mysql_free_result($result);

$posts = array_reverse($posts);

foreach ($posts as $post)
&#123;
$postername = $post&#1111;0];
$postertext = $post&#1111;1];
$posternum = $post&#1111;3];
echo "<b/>$postername Says:</b> $postertext";
echo "<br/>";
&#125;



?>
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Do you need to have

$user = array();
$posts = array();


at before you assign to them with

$user[] = $....
$posts[] = $....


Just a thought
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Post by like_duh44 »

It gets the array from the mysql database. The second one works fine, where it gets the posts, but it doesnt work for the users
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Post by like_duh44 »

I dont know why, but the second query where it gets posts from the mysql database works, but no matter what the first query doesnt work

Please help
Post Reply