Hi i used one of the example in sitepoint https://www.sitepoint.com/creating-a-scrud-system-using-jquery-json-and-datatables/ to create a SCRUD system but the problem is i can only delete the data in mysql and not update and create new data to the database. since its similar so i will just post my query to check wheher its correct or wrong. Additional info: My database is imported form an excel file btw and i have set my primary key as my30_rsl_id with auto increment.
ADD company query:
// Add company
$query = "INSERT INTO my30_rsl SET ";
if (isset($_GET['id'])) { $query .= "id = '" . mysqli_real_escape_string($db_connection, $_GET['id']). "', "; }
if (isset($_GET['SupplierName'])) { $query .= "SupplierName = '" . mysqli_real_escape_string($db_connection, $_GET['SupplierName']) . "', "; }
if (isset($_GET['Commodity'])) { $query .= "Commodity = '" . mysqli_real_escape_string($db_connection, $_GET['Commodity']). "', ";}
if (isset($_GET['SubCategory'])) { $query .= "SubCategory = '" . mysqli_real_escape_string($db_connection, $_GET['SubCategory']). "', "; }
if (isset($_GET['Location'])) { $query .= "Location = '" . mysqli_real_escape_string($db_connection, $_GET['Location']) . "', "; }
if (isset($_GET['Status'])) { $query .= "Status = '" . mysqli_real_escape_string($db_connection, $_GET['Status']) . "', "; }
if (isset($_GET['Supplier_Relationship_Owner'])) { $query .= "Supplier_Relationship_Owner = '" . mysqli_real_escape_string($db_connection, $_GET['Supplier_Relationship_Owner']). "', "; }
if (isset($_GET['Supplier_contact'])) { $query .= "Supplier_contact = '" . mysqli_real_escape_string($db_connection, $_GET['Supplier_contact']). "', "; }
if (isset($_GET['Email_Address'])) { $query .= "Email_Address = '" . mysqli_real_escape_string($db_connection, $_GET['Email_Address']). "', "; }
if (isset($_GET['NPI_or_Production'])) { $query .= "NPI_or_Production = '" . mysqli_real_escape_string($db_connection, $_GET['NPI_or_Production']) . "', "; }
if (isset($_GET['ProtoLeadTime'])) { $query .= "ProtoLeadTime = '" . mysqli_real_escape_string($db_connection, $_GET['ProtoLeadTime']) . "', "; }
if (isset($_GET['Capabilities'])) { $query .= "Capabilities = '" . mysqli_real_escape_string($db_connection, $_GET['Capabilities']) . "', ";}
if (isset($_GET['Strengths'])) { $query .= "Strengths = '" . mysqli_real_escape_string($db_connection, $_GET['Strengths']) . "', ";}
if (isset($_GET['Weaknesses'])) { $query .= "Weaknesses = '" . mysqli_real_escape_string($db_connection, $_GET['Weaknesses']). "', "; }
if (isset($_GET['Costing'])) { $query .= "Costing = '" . mysqli_real_escape_string($db_connection, $_GET['Costing']) . "', "; }
if (isset($_GET['Comments'])) { $query .= "Comments = '" . mysqli_real_escape_string($db_connection, $_GET['Comments']). "', "; }
if (isset($_GET['Indicator'])) { $query .= "Indicator = '" . mysqli_real_escape_string($db_connection, $_GET['Indicator']) . "'"; }
$query = mysqli_query($db_connection, $query);
if (!$query){
$result = 'error';
$message = 'query error';
} else {
$result = 'success';
$message = 'query success';
}
} elseif ($job == 'edit_company'){
the EDIT Company query:
// Edit company
if ($id == ''){
$result = 'error';
$message = 'id missing';
} else {
$query = "UPDATE my30_rsl SET ";
if (isset($_GET['id'])) { $query .= "id = '" . mysqli_real_escape_string($db_connection, $_GET['id']). "', "; }
if (isset($_GET['SupplierName'])) { $query .= "SupplierName = '" . mysqli_real_escape_string($db_connection, $_GET['SupplierName']) . "', "; }
if (isset($_GET['Commodity'])) { $query .= "Commodity = '" . mysqli_real_escape_string($db_connection, $_GET['Commodity']) . "', "; }
if (isset($_GET['SubCategory'])) { $query .= "SubCategory = '" . mysqli_real_escape_string($db_connection, $_GET['SubCategory']) . "', ";}
if (isset($_GET['Location'])) { $query .= "Location = '" . mysqli_real_escape_string($db_connection, $_GET['Location']). "', "; }
if (isset($_GET['Status'])) { $query .= "Status = '" . mysqli_real_escape_string($db_connection, $_GET['Status']) . "', "; }
if (isset($_GET['Supplier_Relationship_Owner'])) { $query .= "Supplier_Relationship_Owner = '" . mysqli_real_escape_string($db_connection, $_GET['Supplier_Relationship_Owner']) . "', ";}
if (isset($_GET['Supplier_contact'])) { $query .= "Supplier_contact = '" . mysqli_real_escape_string($db_connection, $_GET['Supplier_contact']). "', "; }
if (isset($_GET['Email_Address'])) { $query .= "Email_Address = '" . mysqli_real_escape_string($db_connection, $_GET['Email_Address']). "', "; }
if (isset($_GET['NPI_or_Production'])) { $query .= "NPI_or_Production = '" . mysqli_real_escape_string($db_connection, $_GET['NPI_or_Production']) . "', "; }
if (isset($_GET['ProtoLeadTime'])) { $query .= "ProtoLeadTime = '" . mysqli_real_escape_string($db_connection, $_GET['ProtoLeadTime']) . "', "; }
if (isset($_GET['Capabilities'])) { $query .= "Capabilities = '" . mysqli_real_escape_string($db_connection, $_GET['Capabilities']) . "', ";}
if (isset($_GET['Strengths'])) { $query .= "Strengths = '" . mysqli_real_escape_string($db_connection, $_GET['Strengths']) . "', ";}
if (isset($_GET['Weaknesses'])) { $query .= "Weaknesses = '" . mysqli_real_escape_string($db_connection, $_GET['Weaknesses']). "', "; }
if (isset($_GET['Costing'])) { $query .= "Costing = '" . mysqli_real_escape_string($db_connection, $_GET['Costing']) . "', "; }
if (isset($_GET['Comments'])) { $query .= "Comments = '" . mysqli_real_escape_string($db_connection, $_GET['Comments']). "', "; }
if (isset($_GET['Indicator'])) { $query .= "Indicator = '" . mysqli_real_escape_string($db_connection, $_GET['Indicator']) . "'"; }
$query .= "WHERE my30_rsl_id = '" . mysqli_real_escape_string($db_connection, $id) . "'";
$query = mysqli_query($db_connection, $query);
if (!$query){
$result = 'error';
$message = 'query error';
} else {
$result = 'success';
$message = 'query success';
}
}
} elseif ($job == 'delete_company'){
I hope i can find help here because i already spent hours looking for mistake but i cant seem to find it. If the full code is needed i can upload it
data.php (10.6 KB)
index.html (8.4 KB)
layout.css (14.3 KB)
webapp.js (10.8 KB)