I'm trying to get a couple of php if statements to only run when the last fwrite has run. Here's my code snippet:
$cnt = 1;
fwrite($fh, $phptag);
$cnt = 2;
// The last fwrite that I want checked
fwrite($fh, $key);
// Check if write has been successful
if ($fwrite !== false && $cnt == 2) {
$output = json_encode(array( // create JSON data
'type'=>'success',
'text' => 'Congratulations ! The salt key has been successfully created.'
));
exit($output); // exit script outputting json data
}
// Check if write has been unsuccessful
if ($fwrite === false && $cnt == 2) {
$output = json_encode(array( // create JSON data
'type'=>'error',
'text' => 'There has been an error in creating the salt key.'
));
exit($output); // exit script outputting json data
}
I tried using $cnt to control when to run, but the $output is never sent back to the ajax done statement - just getting undefined. What did I do wrong?
Aucun commentaire:
Enregistrer un commentaire