Created
February 23, 2022 14:59
-
-
Save tmoore88/085cca1f0ba6dcbf58b8deb7b80f2511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################### | |
# 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