I'm trying to pull apart an imported csv file, and then each line, check if it exists in the database, for some reason I am getting 'doesnt exist' on every entry, even though the first entry is in fact in the database and should return 'exists'.
if(isset($_GET['uploadfile'])){
$file = fopen($_FILES['csvfile']['tmp_name'], 'r+');
while(! feof($file)){
$line = fgetcsv($file, 0, ',');
list($productcode, $v9cm, $v1litre, $v2litre, $v3litre, $v5litre, $v7litre) = $line;
$sqlcheck = <<<SQL
SELECT `productcode` FROM `stock` WHERE `productcode` = '$productcode'
SQL;
if(!$result = $db->query($sqlcheck)){
echo $productcode.'exists';
}
else {
echo $productcode.'doesnt exist';
}
What is printed onto the screen is TEST1doesnt existsTEST2doesnt existsTEST3doesnt existsTEST4doesnt exists , but what is should say is TEST1 exists ?.