I'm working on a checklist were users can set 4 diffent option on a while cliking on it. When you click once, the is green and display "ok", once more, grey and "N/A", then white and empty. After it starts again to green and "OK" Each time I update my database with the value 1,2,3 or 0 for each possibilities. The javascript works great, color and text are updated correctly in all browsers everytime I click on the For the update of the database, it works as well, until I go back to the white or 0 in the database. I click, it updates to 1, then 2, then 3, then 0, then when you should get 1 it doesn't update it anymore. I don't have this issue with chrome.
Here is the Javascript code :
function CheckLog(TDCheck,ID){
var url;
var Color;
var Status;
var Text;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var TD = document.getElementById("TDCheck"+TDCheck);
if(TD.style.backgroundColor == "white"){
Color = "green";
Status = "1";
Text = "OK";
}
else if(TD.style.backgroundColor == "green"){
Color = "grey";
Status = "2";
Text = "N/A";
}
else if(TD.style.backgroundColor == "grey"){
Color = "red";
Status = "3";
Text = "KO";
}
else if(TD.style.backgroundColor == "red"){
Color = "white";
Status = "0";
Text = "";
}
url="Checklist/checklog.php";
url=url+"?ID="+ID+"&TDCHECK="+TDCheck+"&Status="+Status;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,false);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
xmlHttp.send(null);
document.getElementById("TDCheck"+TDCheck).style.backgroundColor=Color;
document.getElementById("TDCheck"+TDCheck).innerHTML=Text;
}
Checklog.php :
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=dbname', 'database', 'password');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
if(isset($_GET["TDCHECK"]))
{
$bdd->exec("update ChecklistNew SET ".$_GET["TDCHECK"]." = '".$_GET["Status"]."' WHERE ID = '".$_GET["ID"]."'");
}
?>
I have removed PDO in case it was the issue and use mysql_connect, but still the same. By using the response text, I monitor my sql request and I can see one thing :
I click first, the query looks like :
update ChecklistNew SET A2 = '1' WHERE ID = '4'
then
update ChecklistNew SET A2 = '2' WHERE ID = '4'
Then if I update the php file with "update ChecklistNew SET TD = number WHERE ID
= 'Idnum'" (I added quotes arround the ID
)
update ChecklistNew SET A2 = '4' WHERE `ID` = '4'
then
update ChecklistNew SET A2 = '0' WHERE `ID` = '4'
then
update ChecklistNew SET A2 = '1' WHERE ID = '4'
then
update ChecklistNew SET A2 = '2' WHERE ID = '4'
Notice that It kept the previous query. :)... I think there is something there.
I'll appreciate any help!