Skip to content

Instantly share code, notes, and snippets.

@rob2009
Created June 19, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rob2009/01ade64ceac311f7b4e6abd256b0ebfb to your computer and use it in GitHub Desktop.
Save rob2009/01ade64ceac311f7b4e6abd256b0ebfb to your computer and use it in GitHub Desktop.
PHPgrid.org problem using value from POST input
<?php
/**
* PHP Grid Component
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 2.0.0
* @license: see license.txt included in package
*/
include_once("../../config.php");
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
$db_conf = array("type"=> PHPGRID_DBTYPE, "server"=> PHPGRID_DBHOST,"user"=> PHPGRID_DBUSER,"password"=> PHPGRID_DBPASS,"database" => PHPGRID_DBNAME);
if (!empty($_POST["name"]))
{$_SESSION["name"] = $_POST["name"];
$SelectedName = $_SESSION["name"];
}
$SelectedName="Ana";
$searchstring = "SELECT client_id,name FROM clients WHERE name LIKE '%{$SelectedName}%'";
$g = new jqgrid($db_conf);
$g->select_command =$searchstring;
$g->table = "clients";
$col = array();
$col["title"] = "Id"; // caption of column
$col["name"] = "client_id";
$cols[] = $col;
$col = array();
$col["title"] = "Client";
$col["name"] = "name";
$cols[] = $col;
$g->set_columns($cols);
$out = $g->render("list1");
?>
<!DOCTYPE html><head> <meta charset="utf-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head><body>
<?php
echo $out;
echo $searchstring;
?>
<form action="" method="post" name="myForm">
Name:<input id="name" type="name" name="name">
<input type="submit" value="Submit">
</body></html>
@rob2009
Copy link
Author

rob2009 commented Jun 19, 2019

This uses the demo database that comes with phpgrid.org and uses the $_POST handling suggested in FAQ>Misc
As it stands the search returns just the 2 entries that match.
If you comment this out: line 16 $SelectedName="Ana"; and repeat the search with form input name=Ana, in that case the search returns all items in the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment