Bonjour,
Je me sers déjà de ceci pour convertir de fr en us dans un autre script :
$date_fr = $date_us;
$date_us = implode('-',array_reverse (explode('/',$date_fr)));
puis je met un STR_TO_DATE dans ma requête sql. Ca fonctionne parfaitement. J'ai voulu utiliser la même méthode pour une autre appli. mais ça ne fonctionne plus. C'est pourtant identique ?! Je vous joins l'intégralité du code html + php sans la table sql correspondante.
<form method="post" action="" name="formulaire" onsubmit="return validation()";>
<table cellspacing="1" BORDER="0">
<tr>
<th style="white-space: nowrap;" align="left">Date de la visite :<th>
<td><input type="text" name="effectue" id="effectue" size="15" onfocus="view_microcal(true,effectue,microcal5,-1,0);" onblur="view_microcal(false,effectue,microcal5,-1,0);" onkeyup="this.style.color=testTypeDate(this.value)?'black':'red'"></TD>
<td><div id="microcal5" style="visibility:hidden; position:absolute; border:0px red dashed; background:#abe85d;"></div></td>
<td><input type="hidden" name="idchariot" value="<?php echo $total['idchariot'] ?>"></td>
</tr>
<tr>
<th align="left">Socièté :<th>
<td><input type="text" name="societe" value="" size="15"></td>
</tr>
<tr>
<td><input type="submit" name="enregistrer3" value="Enregistrer"></td>
<td style="white-space: nowrap;"><input type= "checkbox" name="type1" value=""> VR 1</td>
<td style="white-space: nowrap;"><input type= "checkbox" name="type2" value=""> VR 2</td>
</tr>
</table>
</form>
<?php
$type1 = $_POST['type1'];
$type2 = $_POST['type2'];
$effectue = $_POST['effectue'];
$societe = $_POST['societe'];
$idchariot = $_POST['idchariot'];
$effectue = $date_fr;
$date_fr = implode('/',array_reverse(explode('-',$effectue)));
if (isset($_POST['enregistrer3']))
{
if (isset($_POST['type1'])){
$req = mysql_query("INSERT INTO suivi_vr (idvr, idchariot, effectue, societe) VALUES ('', '$idchariot', STR_TO_DATE('$effectue', '%d/%m/%Y'), '$societe')");
}
if (isset($_POST['type2'])){
$req2 = mysql_query("INSERT INTO suivi_vr2 (idvr, idchariot, effectue, societe) VALUES ('', '$idchariot', STR_TO_DATE('$effectue', '%d/%m/%Y'), '$societe')");
}
else
echo "<script>alert('Veuillez sélectionner VR1 OU VR2')</script>";
}
?>
Configuration: Linux
Firefox 8.10