I am importing transaction data and saving it into a database. Some of the transaction data has missing fields, so I am manually updating them using the following function from a separate file (file2.php):
function categoryRules() {
//rules for transactions
$sql = "UPDATE Transactions
SET cat1 = 'Shops', cat2 = 'Supermarkets and Groceries'
WHERE name LIKE '%shipt%'";
if (mysqli_query($conn, $sql)) {
echo "SHIPT UPDATE PERFORMED";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$sql = "UPDATE Transactions
SET cat1 = 'Shops', cat2 = 'Food and Beverage Store', cat3 = 'Beer, Wine and Spirits'
WHERE name LIKE '%liquor%'";
if (mysqli_query($conn, $sql)) {
echo "LIQUOR UPDATE PERFORMED";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$sql = "UPDATE Transactions
SET cat1 = 'Service', cat2 = 'Telecommunication Services'
WHERE name LIKE '%vzwrls%'";
if (mysqli_query($conn, $sql)) {
echo "VERIZON UPDATE PERFORMED";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$sql = "UPDATE Transactions
SET cat1 = 'Recreation', cat2 = 'Gyms and Fitness Centers'
WHERE name LIKE '%classpass%'";
if (mysqli_query($conn, $sql)) {
echo "VERIZON UPDATE PERFORMED";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
To clean up my code a bit in file1.php, i am calling the file2 function on file 1.php using:
$conn = mysqli_connect($host, $user, $pass, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
include 'categoryRules.php';
categoryRules();
mysqli_close($conn);
I am getting the following response when doing so:
Error: UPDATE Transactions SET cat1 = 'Shops', cat2 = 'Supermarkets and Groceries' WHERE name LIKE '%shipt%'
Error: UPDATE Transactions SET cat1 = 'Shops', cat2 = 'Supermarkets and Groceries' WHERE name LIKE '%shipt%'
Error: UPDATE Transactions SET cat1 = 'Shops', cat2 = 'Food and Beverage Store', cat3 = 'Beer, Wine and Spirits' WHERE name LIKE '%liquor%'
Error: UPDATE Transactions SET cat1 = 'Service', cat2 = 'Telecommunication Services' WHERE name LIKE '%vzwrls%'
Error: UPDATE Transactions SET cat1 = 'Recreation', cat2 = 'Gyms and Fitness Centers' WHERE name LIKE '%classpass%'
It seems like the functions may be running in file 2.php before they get to file1.php, which is where I open, access, and close the database link. Is there a way to import them into file 1? Is there a better way to clean up this portion of the code for file 1.php besides creating file 2.php?