I have a problem. I'm trying to update a mysql table with data grabbed. The problem is there is an invisible on the end and it's not functioning properly.
DELETE FROM `tracker`.`gains` WHERE `gains`.`runescape_name` = 'Andy FFS
';
DELETE FROM `tracker`.`gains` WHERE `gains`.`runescape_name` = 'Cancerbear
';
DELETE FROM `tracker`.`gains` WHERE `gains`.`runescape_name` = 'Pandora25';
DELETE FROM `tracker`.`gains` WHERE `gains`.`runescape_name` = 'Pether
';
I have a file called memberlist and update.php loops through each line in memberlist.txt and inserts or updates the columns in the table. If you look at the above query (that is just me trouble shooting) I don't actually want to delete it's just to show you the at the end. It's bringing back 0 in all columns except for the name pandora25 (which happens to be at the bottom of memberlist.txt. What I don't understand is I have a php script to edit memberlist.txt on my website, and that's when the problem occurs. But say I open memberlist.txt via SFTP and upload it to my website, it works correctly. So maybe it's something to do with the editing of the txt file with php and it's adding and invisible at the end I'm not sure. But I have studied quite a bit on this issue and I've looked that you can insert into a MySQL table with ->prepare in PDO (I don't use mysqli).
I believe the loop variable [$k] plays an important role in this problem. Here is my code that I seem to be having a problem with:
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tracker';
$userdb = 'root';
$passdb = 'password';
try {
// Connect and create the PDO object
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Query
$sqlquery = ("
INSERT IGNORE INTO
gains (runescape_name, hitpoints_starting_exp, magic_starting_exp, range_starting_exp)
VALUES
('" . htmlspecialchars($name[$k]) . "', '" . $hitpointsexp . "', '" . $magicexp . "', '" . $rangedexp . "')
ON DUPLICATE KEY UPDATE
hitpoints_starting_exp='" . $hitpointsexp . "', magic_starting_exp='" . $magicexp . "', range_starting_exp='" . $rangedexp . "'");
if($conn->exec($sqlquery) !== false) echo 'completed'; // If the result is not false, display confirmation
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
The purpose of this script is to use start.php to insert the current grabbed data into hitpoints_starting_exp, magic_starting_exp and range_starting_exp. I then run stop.php which is a similar script and insert the data grabbed there into hitpoints_end_exp, magic_end_exp and range_end_exp. I then echo a table on index.php which calculates the difference between the two columns.