Hello! I have no idea how to title this question!
I’m trying to populate a grid based on user input from an HTML form.
Here is my code:
<?php
$Number = isset($_POST['Number']) ? $_POST['Number'] : NULL;
$Host = "host";
$User = "user";
$Pass = "password";
$DB = "db";
$dbh = new PDO('dblib:host='.$Host.';dbname='.$DB, $User, $Pass);
require("../../../../includes/dhtmlx/codebase-php/grid_connector.php");
require("../../../../includes/dhtmlx/codebase-php/db_pdo.php");
$grid = new GridConnector($dbh,"PDO");
$sql = "select [columns] from [table] where [key] = ".$Number;
$grid->render_sql($sql, "[ID]", "[columns]");
?>
(edited for security, assume the actual values are different)
This is simply not working at all, and I think it’s because it isn’t getting anything from the $_POST ?
I’m relatively new to PHP so I don’t fully understand how all this works.
I just know that I need to get a value from an HTML form into the SQL statement pictured above and I can’t figure out the best way to do that!
The code on the index is a javascript functions that looks like this:
$('#Number').change(function() {
var num = $(this).val();
$.ajax({
type: 'POST',
url: "autofill.php",
data: { Number: num },
success: function(data) {
if (arr[0].trim() != '') {
$('#title').val(arr[0]);
$('#submitButton').prop("disabled", false);
} else {
$('#submitButton').prop("disabled", true);
}
myGrid.load("connector.php");
},
});
});
The ajax autofills a name in the HTML form based on the number that is typed, and then is supposed to populate the DHTMLX grid in the same action.
I’ve populated grids from ajax calls before, but never with a variable parameter.
Any help appreciated!