So I know that both php and javascript work with cookies and you can create a cookie in php and use that one in javascript.
now I have this code
$csv_file = "filename.csv";
$file_handle = fopen($csv_file, "r");
while (($row_data = fgetcsv($file_handle, 1000, ';')) !== FALSE) {
if (empty($Toevoeging)){
if ($row_data[0] == $Zipcode && $row_data[1] == $Housenumber ) {
$user_input = "User Input Found";
setcookie("user_input", $user_input);
break 1;
}
}else{
if ($row_data[0] == $Zipcode && $row_data[1] == $Housenumber && $row_data[2] == $Toevoeging) {
$user_input = " Found";
setcookie("user_input", $user_input);
break 1;
}else{
$user_input = "User Input NOT Found";
setcookie("user_input", $user_input);
break 1;
}
}
}
fclose($file_handle);
and I know that it works because I used it without cookies and just hard coded it in there for testing perposes (not good at reading csvs) however it's not working anymore. when I show the var in my table
javascript:
var obj = JSON.parse(msg);
var match = document.cookie.match(new RegExp('user_input=([^;]+)'));
var input = decodeURIComponent(match[1]);
var table = $('#displayTable');
$('#displayTable > td').remove();
for (var i = 0; i < Object.keys(obj[0].AvailableSupplier.AvailableSpeeds.AvailableSpeed).length; i++) {
table.append("<tr>");
table.append("<td>" + input + "</td>");
table.append("<td>" + obj[0].AvailableSupplier.AvailableSpeeds.AvailableSpeed[i].Technology + "</td>");
table.append("<td>" + obj[0].AvailableSupplier.AvailableSpeeds.AvailableSpeed[i].Availability + "</td>");
table.append("<td>" + obj[0].AvailableSupplier.AvailableSpeeds.AvailableSpeed[i].Description + "</td>");
table.append("</tr>");
}
it only shows me user input found.
but this is wrong.
the csv check is supposed to check if the entered zipcode and housenumber is in the csv. if they are the user input is found
if the zipcode housenumber and extra letter (don't know the english word sorry example would be: zipcode: 7492 SI Housenumber:34A).
and if they arent in there the user input is not found. this code used to work when I just said echo "user input found" and so on.
how do I fix this
What I have tried:
checkt the internet about cookies. but don't really know what to look up because this is supposed to work.