Im having trouble with the mysql queries inserting rows into the database table, I have the database and all the tables set up and working its just that this script doesnt seem to be inserting the rows.
this scripts purpose is the log the ip's and screennames of people that visit it.
Heres the section of the script that seems to be messing up.
// Basic query to select everything
$MySQL_Result = mysql_query("SELECT * FROM Counts_Info");
// Get a count of all rows selected (All rows)
$Row_Num = mysql_numrows($MySQL_Result);
// Set a simple counter variable
$i = 0;
// Loop over every row
while ($i < $Row_Num) {
// Gather all the data from the current row
$Hit_Number = mysql_result($MySQL_Result, $i, "Hit_Number");
$IP_Address = mysql_result($MySQL_Result, $i, "IP_Address");
$Screen_Name = mysql_result($MySQL_Result, $i, "Screen_Name");
$Date_Time = mysql_result($MySQL_Result, $i, "Date_Time");
// Check to see if the IP Address has already been entered.
if ($IP_Address == $REMOTE_ADDR) {
// If so, then set this boolean to false, we no longer want to add this hit.
$CreateHit = false;
// Check to see if the Screen Name has already been entered.
} elseif ($Screen_Name == $sn) {
// If so, then set this boolean to false, we no longer want to add this hit.
$CreateHit = false;
} else {
// Looks like we will want to create a new hit...
$CreateHit = true;
}
// Create the new hit number.
$New_Hit = $Hit_Number + 1;
// Increase the counter variable.
$i++;
}
// Create a nice looking date/time string - Mon, Jan 1 at 10:11pm
$Formal_Date = date("D, M j ") . 'at' . date(" g:ia");
// Check to see if we want to create a hit...
if ($CreateHit == true) {
// Add the hit into the database.
mysql_query("INSERT INTO `Counts_Info` (`Hit_Number`, `IP_Address`, `Screen_Name`, `Date_Time`) VALUES ('$New_Hit','$REMOTE_ADDR','$sn','$Formal_Date')");
Any help on why its not inserting rows into the table would be helpfull. thx