Page 1 of 1

PHP Chat Problems

Posted: Tue Jul 29, 2003 10:21 am
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;



?>

Posted: Tue Jul 29, 2003 10:51 am
by lazy_yogi
Do you need to have

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


at before you assign to them with

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


Just a thought

Posted: Tue Jul 29, 2003 11:33 am
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

Posted: Tue Jul 29, 2003 1:52 pm
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