Visualizzazione risultati 1 fino 7 di 7

Discussione: problema chat?

  1. #1
    Guest

    Post problema chat?

    ragazzi appena apro la chat del mio sito mi esce questo errore

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /web/htdocs/www.miosito.it/home/prova/shout.php on line 41

    cosa significa?

  2. #2
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,266

    Predefinito

    Significa che il parametro che passi alla mysqli_fetch_array() non è un riferimento mysqli valido. Probabilmente o hai un errore nella query, o c'é un altro errore nel codice. Se non risolvi, posta il codice.

    Ciao!

  3. #3
    Guest

    Predefinito

    grazie mille
    Codice PHP:
    <?php
    ####### db config ##########
    $db_username = 'nome utente';
    $db_password = 'password';
    $db_name = 'nome db';
    $db_host = 'host';
    ####### db config end ##########

    if($_POST)
    {
    //connect to mysql db
    $sql_con = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');

    //check if its an ajax request, exit if not
    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
    die();
    }

    if(isset(
    $_POST["message"]) && strlen($_POST["message"])>0)
    {
    //sanitize user name and message received from chat box
    //You can replace username with registerd username, if only registered users are allowed.
    $username = filter_var(trim($_POST["username"]),FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
    $message = filter_var(trim($_POST["message"]),FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
    $user_ip = $_SERVER['REMOTE_ADDR'];


    //insert new message in db
    if(mysqli_query($sql_con,"INSERT INTO shout_box(user, message, ip_address) value('$username','$message','$user_ip')"))
    {
    $msg_time = date('h:i A M d',time()); // current time
    echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$username.'</span><span class="message">'.$message.'</span></div>';
    }

    // delete all records except last 10, if you don't want to grow your db size!
    mysqli_query($sql_con,"DELETE FROM shout_box WHERE id NOT IN (SELECT * FROM (SELECT id FROM shout_box ORDER BY id DESC LIMIT 0, 10) as sb)");
    }
    elseif(
    $_POST["fetch"]==1)
    {
    $results = mysqli_query($sql_con,"SELECT user, message, date_time FROM (select * from shout_box ORDER BY id DESC LIMIT 10) shout_box ORDER BY shout_box.id ASC");
    while(
    $row = mysqli_fetch_array($results1))
    {
    $msg_time = date('h:i A M d',strtotime($row["date_time"])); //message posted time
    echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$row["user"].'</span> <span class="message">'.$row["message"].'</span></div>';
    }
    }
    else
    {
    header('HTTP/1.1 500 Are you kiddin me?');
    exit();
    }
    }
    Ultima modifica di alemoppo : 16-04-2014 alle ore 18.50.02 Motivo: +tag

  4. #4
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,266

    Predefinito

    Gli dai $result1. Cosa è quella variabile?

    Ciao!

  5. #5
    Guest

    Predefinito

    penso che non serve a niente quella variabile

  6. #6
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,266

    Predefinito

    Molto probabilmente, devi scriverci $result e non $result1 (che non esiste).
    Comunque non usare script fatti, ma falli tu!

    Ciao!

  7. #7
    Guest

    Predefinito

    mi da sempre lo stesso errore :( comunque l'ho scaricato perchè è carino :(

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •