jQWidgets Forums

jQuery UI Widgets Forums Grid Call to a member function bind_param() on bool

This topic contains 10 replies, has 2 voices, and was last updated by  Hristo 4 years, 5 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author

  • paulcobben
    Participant

    Hi,

    I’ve used the demo at https://www.jqwidgets.com/jquery-widgets-documentation/documentation/phpintegration/php-server-side-grid-crud.htm to create a page that has a connection to a database. The page has 2 Grids (Master Details) and in the 1st Grid it has 2 cells per row that can be updated.
    Row gemigreerd is a boolean.
    Row notities is a string.

    When I do an update to a cell i got the error message: Call to a member function bind_param() on bool in C:\xampp\htdocs\DUO\getdata1.php on line 22.
    The correct update query is done to the getdata1.php file. GET /duo/getdata1.php?update=true&ID=3&samaccount=4&gebruikersnaam=Roland+Verheijden&percgereeduser=20&gemigreerd=true&notities=heeft+spoed&uid=3&boundindex=2&uniqueid=2627-24-19-30-242529&visibleindex=2&_=1604865024986

    Here is my getdata1.php

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <title id="Description">DUO Dashboard</title>
        <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
        <script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdata.export.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxmenu.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxpanel.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.filter.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.export.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.columnsresize.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript" src="scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var sourceUsers =
                {
                    datatype: "json",
                    cache: false,
                    datafields: [
                        { name: 'ID', type: 'number' },
                        { name: 'samaccount', type: 'string' },
                        { name: 'gebruikersnaam', type: 'string' },
                        { name: 'percgereeduser', type: 'number' },
                        { name: 'gemigreerd', type: 'bool' },
                        { name: 'notities', type: 'string' }
                    ],
                    id: 'ID',
                    url: './getdata1.php',
                    updaterow: function (rowid, rowdata, commit) {
                    console.log(rowid, rowdata, commit);
                        // synchronize with the server - send update command
                        rowdata.ID = rowid;
                        var data = "update=true&" + $.param(rowdata);
                        $.ajax({
                            dataType: 'json',
                            url: './getdata1.php',
                            cache: false,
                            data: data,
                            success: function (data, status, xhr) {
                                // update command is executed.
                                commit(true);
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                commit(false);
                            }
                        });
                    }
                }
    
                var dataAdapterUsers = new $.jqx.dataAdapter(sourceUsers);
                // initialize jqxGrid
                $("#userGrid").jqxGrid(
                    {
                        width: 1060,
                        height: 400,
                        source: dataAdapterUsers,
                        // theme: 'material',
                        columnsresize: true,
                        showfilterrow: true,
                        sortable: true,
                        filterable: true,
                        editable: true,
                        keyboardnavigation: true,
                        columns: [
                            { text: 'Gebruikersnaam', datafield: 'gebruikersnaam', editable: false, width: 275 },
                            { text: 'User % gereed', datafield: 'percgereeduser', editable: false, width: 125 },
                            { text: 'Gemigreerd', datafield: 'gemigreerd', columntype: 'checkbox', editable: true, width: 100 },
                            { text: 'Notities', datafield: 'notities', editable: true }
                        ]
                    });
    
                // events
    
                // $('#userGrid').on('cellclick', function (event) {
                //     $("#log").html("A cell has been clicked:" + event.args.rowindex + ":" + event.args.datafield);
                // });
    
                // Packages Grid
                // prepare the data
                var sourceDetails =
                {
                    datatype: "json",
                    cache: false,
                    datafields: [
                        { name: 'ID' },
                        { name: 'samaccount' },
                        { name: 'gebruikersnaam' },
                        { name: 'applicatienaam' },
                        { name: 'percgereedpackage' },
                        { name: 'omschrijving' },
                        { name: 'afdeling' },
                        { name: 'actief' },
                        { name: 'typewerkplek' }
                    ],
                    id: 'ID',
                    url: 'getdata2.php',
                };
                var dataAdapterDetails = new $.jqx.dataAdapter(sourceDetails);
                dataAdapterDetails.dataBind();
                $("#userGrid").on('rowselect', function (event) {
                    if (event.args.row) {
                        var samaccount = event.args.row.samaccount;
                        var records = new Array();
                        var length = dataAdapterDetails.records.length;
                        for (var i = 0; i < length; i++) {
                            var record = dataAdapterDetails.records[i];
                            if (record.samaccount == samaccount) {
                                records[records.length] = record;
                            }
                        }
                        var dataSource = {
                            datafields: [
                                { name: 'ID' },
                                { name: 'samaccount' },
                                { name: 'gebruikersnaam' },
                                { name: 'applicatienaam' },
                                { name: 'percgereedpackage' },
                                { name: 'omschrijving' },
                                { name: 'afdeling' },
                                { name: 'actief' },
                                { name: 'typewerkplek' }
                            ],
                            localdata: records
                        }
                        var adapter = new $.jqx.dataAdapter(dataSource);
    
                        // update data source.
                        $("#packageGrid").jqxGrid({ source: adapter });
                    }
                });
    
                // $("#userGrid").on("cellvaluechanged", function (event) {
                //     var selectedrowindex = $("#userGrid").jqxGrid('getselectedrowindex');
                //     var datarow = $("#userGrid").jqxGrid('getrowdata', selectedrowindex);
                    
                //     var rowscount = $("#userGrid").jqxGrid('getdatainformation').rowscount;
                //     if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                //         var id = $("#userGrid").jqxGrid('getrowid', selectedrowindex);
                //         $("#userGrid").jqxGrid('updaterow', id, datarow);
                //     }
                // });
    
                $("#packageGrid").jqxGrid(
                    {
                        width: 1060,
                        autoheight: true,
                        keyboardnavigation: false,
                        columnsresize: true,
                        sortable: true,
                        columns: [
                            { text: 'Gebruikersnaam', columntype: 'textbox', datafield: 'gebruikersnaam' },
                            { text: 'Applicatienaam', columntype: 'textbox', datafield: 'applicatienaam' },
                            { text: 'App % gereed', columntype: 'textbox', datafield: 'percgereedpackage' },
                            { text: 'Omschrijving', columntype: 'textbox', datafield: 'omschrijving' },
                            { text: 'SAM Account naam', columntype: 'textbox', datafield: 'samaccount' },
                            { text: 'Afdeling', columntype: 'textbox', datafield: 'afdeling' },
                            { text: 'Actief', columntype: 'textbox', datafield: 'actief' },
                            { text: 'Type werkplek', columntype: 'textbox', datafield: 'typewerkplek' }
                        ]
                    });
                $("#userGrid").jqxGrid('selectrow', 0);
            });
    
        </script>
    </head>
    
    <body class="default">
        <div id="jqxWidget" style="font-size: 13px; font-family: Verdana; float: left;">
            <h3>
                Gebruikers</h3>
            <div id="userGrid">
            </div>
            <!-- <div id="log"></div>
            <div id="log1"></div> -->
            <h3>
                Details</h3>
            <div id="packageGrid">
            </div>
        </div>
    </body>
    
    </html>

    Table in MySQL is:
    CREATE TABLEsfuser` (
    ID int(11) NOT NULL,
    samaccount text NOT NULL,
    gebruikersnaam text NOT NULL,
    percgereeduser int(11) NOT NULL,
    gemigreerd tinyint(4) NOT NULL,
    notities text NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`

    Hope you can help me?


    paulcobben
    Participant

    Userresult.html was posted above.

    Here is the getdata1.php

    <?php
    #Include the connect.php file
    
    include ('connect.php');
    // Connect to the database
    $mysqli = new mysqli($hostname, $username, $password, $database);
    // $mysqli->set_charset("utf8");
    /* check connection */
    if (mysqli_connect_errno())
    	{
    	printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
    	}
    // get data and store in a json array
    $query = "SELECT ID, samaccount, gebruikersnaam, percgereeduser, gemigreerd, notities FROM sfuser";
    if (isset($_GET['update']))
    {
    	
    	// UPDATE COMMAND
    	$query = "UPDATE 'sfuser' SET 'samaccount'=?, 'gebruikersnaam'=?, 'percgereeduser'=?, 'gemigreerd'=?, 'notities'=?, WHERE 'ID'=?";
    	$result = $mysqli->prepare($query);
    	$result->bind_param('ssiisi', $_GET['samaccount'], $_GET['gebruikersnaam'], $_GET['percgereeduser'], $_GET['gemigreerd'], $_GET['notities'], $_GET['ID']);
    	$res = $result->execute() or trigger_error($result->error, E_USER_ERROR);
    	printf ("Updated Record has id %d.\n", $_GET['ID']);
    	echo $res;
    }
    else 
    {
    	// SELECT COMMAND
    	$result = $mysqli->prepare($query);
    	$result->execute();
     	/* bind result variables */
     	$result->bind_result($ID, $samaccount, $gebruikersnaam, $percgereeduser, $gemigreerd, $notities);
     	/* fetch values */
     	while ($result->fetch())
     		{
     		$sfuser[] = array(
    			'ID' => $ID, 
    			'samaccount' => $samaccount,
     			'gebruikersnaam' => $gebruikersnaam,
     			'percgereeduser' => $percgereeduser,
     			'gemigreerd' => $gemigreerd,
     			'notities' => $notities
     		);
     		}
     	echo json_encode($sfuser);
     	}
    $result->close();
    $mysqli->close();
    /* close connection */
    ?>

    Hristo
    Participant

    Hello paulcobben,

    It seems this is related to the Server-Side scenario.
    Could you check your variables on line 6?
    I think it is related to the discussion on this page.
    I look forward to hearing from you.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    Hi Hristo,

    This is not my problem in my opinion. I can query the database, there’s only a problem with updating.

    Best Regards,
    Paul Cobben


    Hristo
    Participant

    Hello Paul Cobben,

    I would like to suggest you try this approach below for the rowselect event:

    $("#userGrid").on("rowselect", function(event) {
    	if (event.args.row) {
    		var samaccount = event.args.row.samaccount;
    		var records = new Array();
    		var length = dataAdapterDetails.records.length;
    		for (var i = 0; i < length; i++) {
    			var record = dataAdapterDetails.records[i];
    			if (record.samaccount == samaccount) {
    				records[records.length] = record;
    			}
    		}
    		
    		sourceDetails.localdata = records;
    		dataAdapterDetails.dataBind();
    		$("#packageGrid").jqxGrid("updatebounddata");
    	}
    });

    Also, you could move it to the end (after the initialization of the “$(“#packageGrid”)” grid).

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    I am using XAMMP locally for hosting the pages, widgets and database. Root is the account and has all the rights to the database.
    I am able to connect and query the database. Only the update is not working. Please tell me in my code where the problem is.


    Hristo
    Participant

    Hello Paul Cobben,

    Please, try the suggestion from my previous post.
    Also, I would like to add you should include in the initialization of the $("#packageGrid") jqxGrid the source property.
    In the initial state, it should have an empty array for the records.
    After that, just use the methods and options as in the mentioned post above.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    Hi when I add the suggestion in your post, my master-detail functionality breaks. What do you mean exactly written in your last post?


    Hristo
    Participant

    Hello Paul Cobben,

    I mean that in the rowselect event you set the source for the second grid.
    But it could happen before its initialization and the mentioned source’s row could be accepted as such.
    On the other hand, I would like to mention that this should happen just once (if you want to make updates on the jqxGrid it is better to use its methods).
    I tested this previous time and it seems to work fine.
    I would like to suggest you contact the Technical Support Team (support@jqwidgets.com) with your request and provide a simple example of your case.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    I don’t know if you understand my issue. It is not related to the master details setup. This works correctly.
    I only try to update a cell in the 1st table. When I change a cell on the 1st table it gives the correct info to the getdata1.php, but this throws the error.


    Hristo
    Participant

    Hello Paul Cobben,

    We discussed this but I would like to add details in our forum.
    Because it could be useful for others.
    userresult.html:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <title id="Description">DUO Dashboard</title>
        <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
        <link rel="stylesheet" href="jqwidgets/styles/jqx.light-ie.css" type="text/css" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
        <script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdata.export.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxmenu.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxpanel.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.filter.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.export.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxgrid.columnsresize.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript" src="scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var sourceUsers =
                {
                    datatype: "json",
                    cache: false,
                    datafields: [
                        { name: 'ID', type: 'number' },
                        { name: 'samaccount', type: 'string' },
                        { name: 'gebruikersnaam', type: 'string' },
                        { name: 'percgereeduser', type: 'number' },
                        { name: 'gemigreerd', type: 'bool' },
                        { name: 'notities', type: 'string' }
                    ],
                    id: 'ID',
                    url: './getdata1.php',
                    updaterow: function (rowid, rowdata, commit) {                    
                        // synchronize with the server - send update command
                        // rowdata.ID = rowid;
                        var data = "update=true&" + $.param(rowdata);
                        $.ajax({
                            dataType: 'json',
                            url: './getdata1.php',
                            cache: false,
                            data: data,
                            success: function (data, status, xhr) {
                                // update command is executed.
                                commit(true);
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                commit(false);
                            }
                        });
                    },
                    beforeprocessing: function (data) {
                        return data;
                    }
                }
    
                var dataAdapterUsers = new $.jqx.dataAdapter(sourceUsers);
                // initialize jqxGrid
                $("#userGrid").jqxGrid(
                    {
                        width: 1060,
                        height: 400,
                        source: dataAdapterUsers,
                        // theme: 'material',
                        columnsresize: true,
                        showfilterrow: true,
                        sortable: true,
                        filterable: true,
                        editable: true,
                        keyboardnavigation: true,
                        // selectionmode: "singlecell",
                        // editmode: "dblclick",
    
                        selectionmode: "singlerow",
                        editmode: "selectedrow",
    
                        columns: [
                            { text: 'Gebruikersnaam', datafield: 'gebruikersnaam', editable: true, width: 275 },
                            { text: 'User % gereed', datafield: 'percgereeduser', editable: false, width: 125 },
                            { text: 'Gemigreerd', datafield: 'gemigreerd', columntype: 'checkbox', editable: true, width: 100 },
                            { text: 'Notities', datafield: 'notities', editable: true }
                        ]
                    });
            });
    
        </script>
    </head>
    
    <body class="default">
        <div id="jqxWidget" style="font-size: 13px; font-family: Verdana; float: left;">
            <h3>
                Gebruikers</h3>
            <div id="userGrid">
            </div>
            <!-- <div id="log"></div>
            <div id="log1"></div> -->
            <h3>
                Details</h3>
            <div id="packageGrid">
            </div>
        </div>
    </body>
    
    </html>

    getdata1.php:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    #Include the connect.php file
    
    include ('connect.php');
    // Connect to the database
    $mysqli = new mysqli($hostname, $username, $password, $database);
    // $mysqli->set_charset("utf8");
    /* check connection */
    if (mysqli_connect_errno())
    	{
    	printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
    	}
    // get data and store in a json array
    $query = "SELECT ID, samaccount, gebruikersnaam, percgereeduser, gemigreerd, notities FROM sfuser";
    if (isset($_GET['update']))
    {
    	// UPDATE COMMAND
    	$query = "UPDATE sfuser SET samaccount=?, gebruikersnaam=?, percgereeduser=?, gemigreerd=?, notities=? WHERE ID=?";
    	// $query = "UPDATE 'sfuser' SET 'samaccount'=?, 'gebruikersnaam'=?, 'notities'=?, WHERE 'ID'=?";
    	$result = $mysqli->prepare($query);
    	// $result->bind_param('isissi', $_GET['samaccount'], $_GET['gebruikersnaam'], $_GET['percgereeduser'], $_GET['gemigreerd'], $_GET['notities'], (int)$_GET['ID']);
    	// $gemigreerd = $_GET['gemigreerd'] ? 1 : 0;
    	// echo "\n" . $gemigreerd . "$-gemigreerd \n";
    	// $newValue = $_GET['gemigreerd'] ? 1 : 0;
    	
    	$newValue = 0;
    	if ($_GET['gemigreerd'] === "true") {
    		$newValue = 1;
    	} else {
    		$newValue = 0;
    	}
    	
    	// // printf($newValue . " - \$newValue \n" . $_GET['gemigreerd']);
    	// printf($_GET['gemigreerd'] . " - " . $newValue);
    	// printf($_GET['gemigreerd']);
    
    	$result->bind_param('ssiisi', $_GET['samaccount'], $_GET['gebruikersnaam'], $_GET['percgereeduser'], $newValue, $_GET['notities'], $_GET['ID']);
    
    	// if ($result) {
    	// 	// $result->bind_param('ssi', $_GET['gebruikersnaam'], $_GET['notities'], $id);
    	// 	$result->bind_param('ssissi', $_GET['samaccount'], $_GET['gebruikersnaam'], $_GET['percgereeduser'], $_GET['gemigreerd'], $_GET['notities'], $_GET['ID']);
    	// 	$res = $result->execute() or trigger_error($result->error, E_USER_ERROR);
    	// 	printf ("Updated Record has id %d.\n", $_GET['ID']);
    	// 	echo $res;
    	// } else {
    	// 	$error = $mysqli->errno . ' ' . $mysqli->error;
        // 	echo $error;
    	// }
    	
    	// $result->bind_param('ssi', $_GET['gebruikersnaam'], $_GET['notities'], $id);
    	$res = $result->execute() or trigger_error($result->error, E_USER_ERROR);
    	// printf ("Updated Record has id %d.\n", $_GET['ID']);
    	
    	echo $res;
    	// echo json_encode($res);
    }
    else 
    {
    	// SELECT COMMAND
    	$result = $mysqli->prepare($query);
    	$result->execute();
     	/* bind result variables */
     	$result->bind_result($ID, $samaccount, $gebruikersnaam, $percgereeduser, $gemigreerd, $notities);
     	/* fetch values */
     	while ($result->fetch())
     		{
     		$sfuser[] = array(
    			'ID' => $ID, 
    			'samaccount' => $samaccount,
     			'gebruikersnaam' => $gebruikersnaam,
     			'percgereeduser' => $percgereeduser,
     			'gemigreerd' => $gemigreerd,
     			'notities' => $notities
     		);
     		}
     	echo json_encode($sfuser);
     	}
    $result->close();
    $mysqli->close();
    /* close connection */
    

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.