I met a trouble with a script I have done.
Here is the entire script. But the trouble concern only 2 lines.
In fact I have a PHP condition if it is respected it should display an alert if not, it should execute the following script.
and at the end I have a header location that makes the user go back to the previous page.
The thing is that it does not display the alert, it directly make the user go back. I would like to make the user click on 'ok' in order to make the script continue. Is there a way I can do that.?
<?php
$sql="SELECT SUM(montant) as montantfactures, n_doss
FROM `factures`
WHERE `n_doss`='".mysql_real_escape_string($_GET['n_doss'])."'
GROUP BY `n_doss`";
$result=mysql_query($sql) or die;
while($data=mysql_fetch_assoc($result))
{
$rqt="SELECT `interets`.*,
`les_taux`.*,
`decompte`.`principal_s`
FROM `interets`
INNER JOIN `les_taux` ON `interets`.`type`=`les_taux`.`type`
INNER JOIN `decompte` ON `interets`.`n_doss`=`decompte`.`n_doss`
WHERE `interets`.`n_doss`='".$data['n_doss']."'
GROUP BY `date_modif` DESC
LIMIT 1";
$resultat=mysql_query($rqt) or die;
$donnees=mysql_fetch_assoc($resultat);
{$datefin=$donnees['date_fin'];}
$datedepart=$donnees['date_depart'];
if($donnees['date_fin']==date('Y-m-d'))
{
echo "<script type=\"text/javascript\">alert(\"les interets sont deja a jour\")</script>";
}
else
{
if($donnees['type']=='tc')
{
if($donnees['montant']==0)
{
$taux=($donnees['valeur']*1);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*$nbjours*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'
";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
else
{
$taux=($donnees['valeur']*1);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*1*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
}
elseif($donnees['type']=='tleg')
{
if($donnees['montant']==0)
{
if($donnees['operateur']=="x")
{
$taux=($donnees['valeur']*$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*$nbjours*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
elseif($donnees['operateur']=="+")
{
$taux=($donnees['valeur']+$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*$nbjours*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
}
else
{
if($donnees['operateur']=="x")
{
$taux=($donnees['valeur']*$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*1*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
elseif($donnees['operateur']=="+")
{
$taux=($donnees['valeur']+$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*1*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
}
}
elseif($donnees['type']=='tbce')
{
if($data['montantfactures']==0)
{
if($donnees['operateur']=="x")
{
$taux=($donnees['valeur']*$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*$nbjours*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
elseif($donnees['operateur']=="+")
{
$taux=($donnees['valeur']+$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*$nbjours*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
}
else
{
if($donnees['operateur']=="x")
{
$taux=($donnees['valeur']*$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*1*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
elseif($donnees['operateur']=="+")
{
$taux=($donnees['valeur']+$donnees['variable']);
$nbjours=round((strtotime($datefin) - strtotime($datedepart))/(60*60*24)-1);
$interets=(($data['montantfactures']-$donnees['principal_s'])*1*$taux)/(365*100);
$nouveauinterets=$donnees['montant']+$interets ;
$itc="UPDATE `interets` SET
montant = '".$nouveauinterets."',
date_fin= NOW() WHERE n_doss='".$donnees['n_doss']."'";
$rtq = mysql_query($itc) or die(__LINE__.mysql_error().$itc);
echo "<img src='images/tick_48.png' width='24'> Intérêts correctement mis à jour pour le dossier n°".$donnees['n_doss'].'<br>' ;
}
}
}
}
}
header('Location: ' . $_SERVER['HTTP_REFERER'] );
?>
if(donnees['date-fin']==date('Y-m-d'))line?header('Location:');is what stops your script from producing any output. The way it works is this: you ask for something from the server and server replies. It sends the headers to notify your browser what happened (resource found, not found, moved etc) and it sends the response (the thing you tried toecho). Since headers are parsed first, the browser will notice theLocationheader and it will redirect you because it won't try to present the content (in your case - the JS with the alert in it).