Skip to content

Instantly share code, notes, and snippets.

@tmoore88
Created February 23, 2022 14:59
Show Gist options
  • Save tmoore88/085cca1f0ba6dcbf58b8deb7b80f2511 to your computer and use it in GitHub Desktop.
Save tmoore88/085cca1f0ba6dcbf58b8deb7b80f2511 to your computer and use it in GitHub Desktop.
#####################
# ON EDIT/ADD EVENT #
#####################
function add_edit_fk($data)
{
////////////////////////
// GLOBAL VARIABLE(S) //
////////////////////////
global $g;
global $conn;
//phpgrid_error("Error message");
/////////////////////////////////////
// SET COLUMN TO UPPER CASE ON ADD //
/////////////////////////////////////
$data["params"]["First_name"] = strtoupper($data["params"]["First_name"]);
$data["params"]["Last_name"] = strtoupper($data["params"]["Last_name"]);
$data["params"]["company_name"] = strtoupper($data["params"]["company_name"]);
///////////////////////////////
// AUTOCOMPLETE COMPANY NAME //
///////////////////////////////
$n = $data["params"]["company_name"];
$ss = $g->get_one("SELECT * FROM tbl_customer WHERE company_name='$n'"); #<-This Works
//$ss = $g->get_one("SELECT * FROM tbl_customer WHERE company_name=?",array($n)); #<-This does not work anymore
if (empty($ss))
{
unset($data["params"]["fk_customer_id"]);
//$insert_id = $g->execute_query("INSERT INTO tbl_customer (company_name) VALUES (?)",array($n),"insert_id"); #<- this does not work anymore
// $g->execute_query("INSERT INTO tbl_customer (company_name) VALUES ('$n')"); #<-This works, but could not get it to return insert ID
//My Query below Works
$sql = mysqli_query($conn, "INSERT INTO tbl_customer (company_name) VALUES ('$n')");
$last_id = mysqli_insert_id($conn);
$data["params"]["fk_customer_id"] = $last_id;
}
/////////////////////////////////////////////////////////////
// UNSET ALL COLUMNS THAT DONOT BELONG TO DEFAULT DATABASE //
/////////////////////////////////////////////////////////////
unset($data["params"]["company_name"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment