[PHP] JTable Errore

Lalli

Nuovo Utente
6 Ott 2016
15
0
1
28
Ciao raga, stavo pensando di usare jtable per il mio programma , ho trovato un esempio di jtable e l'ho personalizzato. solo che quando vado ad eseguirlo su chrome mi dice "An error occured while communicating to the server." e non riesco a capire dove sbaglio. Vi viene in mente qualcosa a voi? qui di seguito posto il codice.
Questa parte è la connessione con le varie Select :
PHP:
<?php

try
{
    $pass="";
    //Open database connection
    $con = mysql_connect("localhost","root",$pass);
    mysql_select_db("hardwarea", $con);

    //Getting records (listAction)
    if($_GET["action"] == "list")
    {
        //Get records from database
        $result = mysql_query("SELECT * FROM gestione;");
        
        //Add all records to an array
        $rows = array();
        $ris= mysql_query($stmt) or die($stmt."<br/><br/>".mysql_error());
            
        while($rows=mysql_fetch_array($ris))
        {
            echo" <tr> <td> " . $rows['ID'] . " </td> <td> " . $rows['Filiale'] . " </td> <td> " . $rows['Ufficio'] . " </td> <td> " . $rows['Utente'] . " </td> <td> " . $rows['Tipo'] . " </td> <td> " . $rows['Marca'] . " </td> <td> " . $rows['Modello'] . " </td> <td> " . $rows['Matricola'] . " </td> <td> " . $rows['Note'] . " </td> <td> " . $rows['DataDDT'] . " </td> <td> " . $rows['DDT'] . " </td><td> " . $rows['Fornitore'] . " </td> <td> " . $rows['ACQNOL'] . " </td> <td> " . $rows['Scadenza'] . " </tr>";
        }   

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        $jTableResult['Records'] = $rows;
        print json_encode($jTableResult);
    }
    //Creating a new record (createAction)
    else if($_GET["action"] == "create")
    {
        //Insert record into database
        $result = mysql_query("INSERT INTO gestione(Filiale, Ufficio, Utente, Tipo, Marca, Modello, Matricola, Note, DataDDT, DDT, Fornitore, ACQNOL, Scadenza) VALUES('" . $_POST["Filiale"] . "', " . $_POST["Ufficio"] . "'" . $_POST["Utente"] . "', " . $_POST["Tipo"] . "'" . $_POST["Marca"] . "', " . $_POST["Modello"] . "'" . $_POST["Marca"] . "', " . $_POST["Modello"] . "'" . $_POST["Matricola"] . "', " . $_POST["Note"] . "'" . $_POST["DataDDT"] . "', " . $_POST["DDT"] . "'" . $_POST["Fornitore"] . "', " . $_POST["ACQNOL"] . "'" . $_POST["Scadenza"] . ",now());");
        
        //Get last inserted record (to return to jTable)
        $result = mysql_query("SELECT * FROM gestione WHERE ID = LAST_INSERT_ID();");
        $row = mysql_fetch_array($result);

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        $jTableResult['Record'] = $row;
        print json_encode($jTableResult);
    }
    //Updating a record (updateAction)
    else if($_GET["action"] == "update")
    {
        //Update record in database
        $result = mysql_query("UPDATE gestione SET Filiale = '" . $_POST["Filiale"] . "', Ufficio = " . $_POST["Ufficio"] .  "', Utente = " . $_POST["Utente"] .  "', Tipo = " . $_POST["Tipo"] .  "', Marca = " . $_POST["Marca"] .  "', Modello = " . $_POST["Modello"] .  "', Matricola = " . $_POST["Matricola"] .  "', Note = " . $_POST["Note"] .  "', DataDDT = " . $_POST["DataDDT"] .  "', DDT = " . $_POST["DDT"] .  "', Fornitore = " . $_POST["Fornitore"] .  "', ACQNOL = " . $_POST["ACQNOL"] .  "', Scadenza = " . $_POST["Scadenza"] .  "  WHERE ID = " . $_POST["ID"] . ";");

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        print json_encode($jTableResult);
    }
    //Deleting a record (deleteAction)
    else if($_GET["action"] == "delete")
    {
        //Delete from database
        $result = mysql_query("DELETE FROM gestione WHERE ID = " . $_POST["ID"] . ";");

        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        print json_encode($jTableResult);
    }

    //Close database connection
    mysql_close($con);

}
catch(Exception $ex)
{
    //Return error message
    $jTableResult = array();
    $jTableResult['Result'] = "ERROR";
    $jTableResult['Message'] = $ex->getMessage();
    print json_encode($jTableResult);
}
    
?>

Quest'altra invece è la parte e la struttura della tabella diciamo e i richiami dei vari Insert Update e Delete
PHP:
<html>
  <head>

    <link href="themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <link href="Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />
    
    <script src="scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script src="scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
    
  </head>
  <body>
    <div id="PeopleTableContainer" style="width: 600px;"></div>
    <script type="text/javascript">

        $(document).ready(function () {

            //Prepare jTable
            $('#PeopleTableContainer').jtable({
                title: 'Tabella Hardware',
                actions: {
                    listAction: 'PersonActions.php?action=list',
                    createAction: 'PersonActions.php?action=create',
                    updateAction: 'PersonActions.php?action=update',
                    deleteAction: 'PersonActions.php?action=delete'
                },
                fields: {
                    ID: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                     Filiale: {
                    title: 'Filiale',
                    width: '40%'
                },
                Ufficio: {
                    title: 'Ufficio',
                    width: '40%'
                },
                Utente: {
                    title: 'Utente',
                    width: '40%',
                },
                Tipo: {
                    title: 'Tipo',
                    width: '40%'
                },
                Marca: {
                    title: 'Marca',
                    width: '40%'
                },
                Modello: {
                    title: 'Modello',
                    width: '40%'
                },
                Matricola: {
                    title: 'Matricola',
                    width: '40%'
                },
                Note: {
                    title: 'Note',
                    width: '40%'
                },
                DataDDT: {
                    title: 'DataDDT',
                    width: '40%'
                },
                DDT: {
                    title: 'DDT',
                    width: '40%'
                },
                Fornitore: {
                    title: 'Fornitore',
                    width: '40%'
                },
                ACQNOL: {
                    title: 'ACQNOL',
                    width: '40%'
                },
                Scadenza: {
                    title: 'Scadenza',
                    width: '40%'
                },
                }
            });

            //Load person list from server
            $('#PeopleTableContainer').jtable('load');

        });

    </script>
 
  </body>
</html>
 

Discussioni simili