I have set up this code that finally works in all aspects in the way I expected it to work except for one thing, the last 'if' doesn't write the values to the database. I know it is validating and is running the sql_query yet nothing shows up in the db. What did I do wrong?????
the code:
PHP Code:
while(!feof($fh))
{
$line = fgets($fh,1024);
list($fcode) = explode("/n", $line);
$b='2';
$a = (int)substr($line, 0, 1);
if (substr($fcode, 0, 4) === "HEAD")
{
$sql = "INSERT INTO parsed_files (header_id) VALUES ('$fcode')";
mysql_query($sql);
}
if ($a>0)
{
$check=substr($fcode, 0, 11);
$table = mysql_query("SELECT code_id,valid_cust_code,current_points_earned,total_points_earned FROM codes");
while ($row = mysql_fetch_assoc($table))
{
$dataBaseValue=stripslashes($row['valid_cust_code']);
$updateIdentifier=($row['code_id']);
$currentTotal=stripslashes($row['current_points_earned']);
$totalEarned=stripslashes($row['total_points_earned']);
if ($dataBaseValue === $check)
{
$b='3';
$currentTotal++;
$totalEarned++;
$sql = 'UPDATE codes SET current_points_earned = '.$currentTotal.', total_points_earned = '.$totalEarned.' WHERE code_id = '.$updateIdentifier.' LIMIT 1';
mysql_query($sql);
}
}
if ($b==='2')
{
echo 'we made it '.$fcode.'<br />';
$Total='1';
$Earned='1';
$sql = "INSERT INTO 'codes' (`code_id`, `valid_cust_code`, `current_points_earned`, `total_points_earned`) VALUES ('', '$fcode', '$Total', '$Earned')";
mysql_query($sql);
}
}
}
fclose($fh);
//unlink($datFile);
mysql_close($dbconnect);
|