Visualizzazione risultati 1 fino 12 di 12
Like Tree1Likes
  • 1 Post By karl94

Discussione: Problema col database

  1. #1
    Guest

    Predefinito Problema col database

    Ciao. Sto tentando di mettere una lista ban su Altervista ma non riesco perché, nonostante io abbia messo i dati nel config.php, mi dice che non trova il database (il file ha bisogno del database MySQL)

  2. #2
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Riporta il codice che stai utilizzando.

  3. #3
    Guest

    Predefinito

    https://s293.altervista.org/edita.pl...&FH=config.php
    Questo è il file config.php dove ho inserito tutti i dati del mio database
    e questo è il file index.php che dipende dal config.php
    https://s293.altervista.org/edita.pl...p&FH=index.php

  4. #4
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    Non puoi usare il collegamento all'editor del pannello di controllo in questo modo (il quale è "legato" alla tua sessione), devi mostrare il contenuto dei file.

  5. #5
    Guest

    Predefinito

    Codice PHP:
    <?php
    // ### ######## ## ## ### ## ## ###### ######## ######## ######## ### ## ##
    // ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ### ##
    // ## ## ## ## ## ## ## ## #### ## ## ## ## ## ## ## ## ## #### ##
    // ## ## ## ## ## ## ## ## ## ## ## ## ###### ## ## ######## ## ## ## ## ##
    // ######### ## ## ## ## ######### ## #### ## ## ## ## ## ## ######### ## ####
    // ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ###
    // ## ## ######## ### ## ## ## ## ###### ######## ######## ######## ## ## ## ##
    // In this file you can edit some content of the webside
    // If you want to edit the layout you have to go in to 'style.css' | CCS-Skills required
    // For any help, feedback, bug-reports or questions feel free to contact me via PM on Spigot/BukkitDev or to add me on Skype: Leoko33
    // I hope you like my WebPanel <3

    ////////////////////////////////////////////////
    // MySQL-Data //
    // //

    //Database-Name
    define("DB_NAME", " my_mcminecrew");

    //MySQL- Server-IP/Domanin
    define("HOST", "localhost");

    //MySQL-Account
    define("USERNAME", "mcminecrew");
    define("PASSWORD", "************");

    // //
    ////////////////////////////////////////////////


    ////////////////////////////////////////////////
    // General //
    // //

    //Show who banned the player
    //"Banned by"-Tag
    define("BANNED_BY", true);

    //Change the way the date is displayed
    //This can get VERY buggy if the format
    //is too long. GER-Format: "d.m H:i"
    define("DATE_FORMAT", "m/d H:i");

    //Amount of Entries showed on the
    //main-page. [Ban, Tempbans, Kicks]
    define("MAX_ENTRIES", 10);

    //WebSide-Title showed in the tab
    define("TITLE", "Lista ban NonnoCraft");

    // //
    ////////////////////////////////////////////////

    ////////////////////////////////////////////////
    // Language //
    // //

    //Language of this web application
    //Supported: en, cs, de
    define("LANG", "en");

    //Language loader - do not change
    require "lang/". LANG .".php";

    // //
    ////////////////////////////////////////////////

    // no ending tag to avoid accidental output
    Ho censurato solo la mia password
    Ultima modifica di karl94 : 10-08-2016 alle ore 13.58.40 Motivo: Formattazione

  6. #6
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    In questo momento non ricordo se il nome della base di dati sia case-sensitive, ma credo di sì. Il nome dovrebbe allora essere:
    Codice PHP:
    define("DB_NAME", "my_MCMineCrew");
    Se questo non risolve il problema, mostra anche il contenuto del file index.php.

  7. #7
    Guest

    Predefinito

    Citazione Originalmente inviato da mzanella Visualizza messaggio
    In questo momento non ricordo se il nome della base di dati sia case-sensitive, ma credo di sì. Il nome dovrebbe allora essere:
    Codice PHP:
    define("DB_NAME", "my_MCMineCrew");
    Se questo non risolve il problema, mostra anche il contenuto del file index.php.
    Se funziona ti faccio santo xD

  8. #8
    Guest

    Predefinito

    No, purtroppo non funzia, ecco il file index.php:

    Codice PHP:
    <?php
    require 'config.php';
    if (
    $link = mysql_connect(HOST, USERNAME, PASSWORD)) {} else {
    die(
    "<br><h2 style="text-align:center;color:red">Error while connecting to MySQL database</h2><h3 style="text-align:center;color:red">Check MySQL connection in config.php</h3>");
    }
    if (
    mysql_select_db(DB_NAME, $link)) {} else {
    die(
    "<br><h2 style="text-align:center;color:red">Error while selecting MySQL database</h2><h3 style="text-align:center;color:red">Check if database exists and user from config.php has access to it</h3>");
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title><?php echo TITLE; ?></title>
    <link rel="shortcut icon" type="image/x-icon" href="img/ico.png">
    <link rel="stylesheet" href="style.css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=0.5, width=device-width">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    </head>
    <?php
    function calcTime($d1, $d2){
    require
    'config.php';
    $interval = $d2->diff($d1);
    if (
    $v = $interval->d >= 1 ) return $interval->d.' d';
    if (
    $v = $interval->h >= 1 ) return $interval->h.' h';
    if (
    $v = $interval->i >= 1 ) return $interval->i.' min';
    return
    $interval->s.' sec';
    }

    function
    getBanOrKick($id, $time, $name, $reason, $by, $end){
    require
    'config.php';
    $addition = "";
    if(
    $end != ""){
    $addition = '<tr class="hide-'.$id.'" >
    <td style="text-align:right;color:#9EFF30;">'
    .$msgDuration.'</td> <td class="color2">"'.$end.'"</td>
    </tr>'
    ;
    }
    echo
    '
    <tr class="name-'
    .$id.'" style="cursor: pointer;">
    <td class="color2" style="text-align:right;width:100px;font-size:20px;">
    '
    .$time.'
    </td>
    <td>
    <span class="reason-entry" >'
    .$name.'</span>*<i style="font-size:15px;" class="fa fa-mouse-pointer"></i>
    </td>
    </tr>
    <tr class="hide-'
    .$id.'" >
    <td style="text-align:right;color:orange;">'
    .$msgReason.'</td> <td class="color2">"'.$reason.'"</td>
    </tr>'
    ;
    if(
    BANNED_BY){
    echo
    '<tr class="hide-'.$id.'" >
    <td style="text-align:right;color:#3194CE;">'
    .$msgBannedBy.'</td> <td class="color2">"'.$by.'"</td>
    </tr>'
    ;
    }

    echo
    $addition.'

    <style>
    .hide-'
    .$id.'{
    font-size: 0px;

    transition-timing-function: ease-out;
    -webkit-transition-timing-function: ease-out;

    -webkit-transition: 0.5s;
    transition: 0.5s;
    }

    #main .name-'
    .$id.':hover ~ .hide-'.$id.'{
    font-size: 25px;
    }
    </style>
    '
    ;
    }

    ?>
    <body>
    <div class="shadow" id="header">
    <span id="title" ><?php echo $msgTitle; ?></span>
    <form id="ban-search" method="get" action="search.php">
    <span><?php echo $msgSearch; ?> </span><input name="search" type="text" required><i onclick="document.getElementById('ban-search').submit();" class="whiteIco fa fa-search"></i>
    </form>
    </div>
    <br>
    <br>
    <div id="main">
    <table style="width:400px;">
    <tr>
    <th style="text-align:right;"> <i class="fa fa-lock"></i> </th>
    <th style="text-align:left;">
    <?php echo $msgLastBans; ?>
    </th>
    </tr>
    <?php
    //BAN
    $sql="SELECT * FROM PlayerHistory WHERE end='BAN' ORDER BY STR_TO_DATE(`PlayerHistory`.`start`, '%d.%m.%Y-%H:%i:%s') DESC LIMIT ". MAX_ENTRIES;
    $result=mysql_query($sql,$link);
    if(
    mysql_num_rows($result)>0) {
    for(
    $i=0;$i<mysql_num_rows($result);$i++) {
    //07.10.2015-14:25:46
    $date = DateTime::createFromFormat('d.m.Y-H:i:s', mysql_result($result,$i,'start'));
    getBanOrKick(($i."b"),
    $date->format(DATE_FORMAT),
    mysql_result($result,$i,'name'),
    mysql_result($result,$i,'reason'),
    mysql_result($result,$i,'by'), '');
    }
    }else{
    echo
    '
    <tr><td></td><td style="color:#FF6C59; font-size: 25px;">'
    .$msgNoBans.'</td></tr>
    '
    ;
    }
    ?>
    </table>

    <table style="width:400px;">
    <tr>
    <th style="text-align:right;" > <i class="fa fa-ban"></i> </th>
    <th style="text-align:left;">
    <?php echo $msgLastKicks; ?>
    </th>
    </tr>
    <?php
    //KICK
    $sql="SELECT * FROM PlayerHistory WHERE end='KICK' ORDER BY STR_TO_DATE(`PlayerHistory`.`start`, '%d.%m.%Y-%H:%i:%s') DESC LIMIT ".MAX_ENTRIES;
    $result=mysql_query($sql,$link);
    if(
    mysql_num_rows($result)>0) {
    for(
    $i=0;$i<mysql_num_rows($result);$i++) {
    //07.10.2015-14:25:46
    $date = DateTime::createFromFormat('d.m.Y-H:i:s', mysql_result($result,$i,'start'));
    getBanOrKick(($i."k"),
    $date->format(DATE_FORMAT),
    mysql_result($result,$i,'name'),
    mysql_result($result,$i,'reason'),
    mysql_result($result,$i,'by'), '');
    }
    }else{
    echo
    '
    <tr><td></td><td style="color:#FF6C59; font-size: 25px;">'
    .$msgNoKicks.'</td></tr>
    '
    ;
    }
    ?>
    </table>

    <table style="width:400px;">
    <tr>
    <th style="text-align:right;"> <i class="fa fa-clock-o"></i> </th>
    <th style="text-align:left;">
    <?php echo $msgLastTempBans; ?>
    </th>
    </tr>
    <?php
    //TEMP-BAN
    $sql="SELECT * FROM PlayerHistory WHERE end NOT IN ('BAN', 'KICK') ORDER BY STR_TO_DATE(`PlayerHistory`.`start`, '%d.%m.%Y-%H:%i:%s') DESC LIMIT ".MAX_ENTRIES;
    $result=mysql_query($sql,$link);
    if(
    mysql_num_rows($result)>0) {
    for(
    $i=0;$i<mysql_num_rows($result);$i++) {
    //07.10.2015-14:25:46
    $date = DateTime::createFromFormat('d.m.Y-H:i:s', mysql_result($result,$i,'start'));
    $end = DateTime::createFromFormat('d.m.Y-H:i:s', mysql_result($result,$i,'end'));
    getBanOrKick(($i."t"),
    $date->format(DATE_FORMAT),
    mysql_result($result,$i,'name'),
    mysql_result($result,$i,'reason'),
    mysql_result($result,$i,'by'),
    calcTime($date ,$end));
    }
    }else{
    echo
    '
    <tr><td></td><td style="color:#FF6C59; font-size: 25px;">'
    .$msgNoTempBans.'</td></tr>
    '
    ;
    }
    ?>
    </table>
    </div>
    <div id="footer" class="shadow">
    <span>Coded by <a href="http://dev.skamps.eu" target="_blank">LeokoTime</a> | © Copyright 2015</span>
    </div>
    </body>
    </html>
    Ultima modifica di karl94 : 10-08-2016 alle ore 13.59.06 Motivo: Formattazione

  9. #9
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    A prima vista sembra abbastanza corretto.
    Prima di dare un'occhiata più approfondita, nel file config.php ho notato che c'è uno spazio di troppo prima del nome del database (oltre al case-sensitivity):
    Codice PHP:
    define("DB_NAME", " my_mcminecrew");
    anziché
    Codice PHP:
    define("DB_NAME", "my_MCMineCrew");
    sarà un'osservazione banale ma credo valga comunque la pena controllare...

  10. #10
    Guest

    Predefinito

    Citazione Originalmente inviato da mzanella Visualizza messaggio
    A prima vista sembra abbastanza corretto.
    Prima di dare un'occhiata più approfondita, nel file config.php ho notato che c'è uno spazio di troppo prima del nome del database (oltre al case-sensitivity):
    Codice PHP:
    define("DB_NAME", " my_mcminecrew");
    anziché
    Codice PHP:
    define("DB_NAME", "my_MCMineCrew");
    sarà un'osservazione banale ma credo valga comunque la pena controllare...
    non va :/

  11. #11
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    Ho provato il codice nel mio spazio e sembra funzionare: http://mzanella.altervista.org/a.php (ovviamente segnala gli errori relativi al fatto che la mia base di dati non contiene le tabelle necessarie).


    Puoi ottenere più informazioni sull'errore sostituendo le seguenti righe:
    Codice PHP:
    if (mysql_select_db(DB_NAME, $link)) {} else {
    die(
    "<br><h2 style=\"text-align:center;color:red\">Error while selecting MySQL database</h2><h3 style=\"text-align:center;color:red\">Check if database exists and user from config.php has access to it</h3>");
    }
    con:
    Codice PHP:
    if (mysql_select_db(DB_NAME, $link) === false) {
    die(
    "<br><h2 style='text-align:center;color:red'>Error while selecting MySQL database</h2>
    <h3 style='text-align:center;color:red'>Check if database exists and user from config.php has access to it</h3>"
    . mysql_error());
    }
    Prova ad eseguirlo con questa modifica e vediamo quale messaggio d'errore viene mostrato.

    PS: Ricordavo bene ed il nome della base di dati è case-sensitive.

  12. #12
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Il problema era lo spazio, adesso però il nuovo problema sono le maiuscole: il nome del database su AlterVista è tutto in minuscolo.
    mzanella likes this.

Regole di scrittura

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