validation aprés clic sur buton submit
Bonjour
J’ai besoin de votre aide car je suis bloqué avec mon script et j’arrive pas a avancer
Voici mon problème :
J’ai un scripte qui insère les données dans une base mysql à partir d’un formulaire web, mais mon problème est que l’insertion se fait dés que j’appelle le formulaire à travers son lien et la base effectue un enregistrement vide pourtant moi j’aimerais que l’enregistrement ne se fasse que si je clique sur le boutton submit aprés avoir remplis mon formulaire
Si quelqu’un a une idée peut il m’aider en modifiant mon code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
error_reporting(E_ALL ^E_NOTICE);
// On insére dans des variables les coordonnées de votre compte //
// qui permettront l'insertion dans la base //
$sql_serveur="localhost";
$sql_user="root";
$sql_passwd="";
$sql_bdd="incidence";
// on lance la requete de connection à la base
$connect = mysql_connect($sql_serveur,$sql_user,$sql_passwd);
// on verifie que la connection à réussie
if(!$connect)
{echo "Connection impossible vérifiez vos coordonnées de connection !!!";exit;}
// on selectionne la base de donnée ou se trouve votre table "membreé
mysql_select_db("incidence");
// votre requete d'insertion
$ref=$_POST['ref'];
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$fonction=$_POST['fonction'];
$type=$_POST['type'];
$assignation=$_POST['assignation'];
$responsable=$_POST['responsable'];
$acteur=$_POST['acteur'];
$date=$_POST['date'];
$description=$_POST['description'];
////////Formatage de la date
$d=explode("/",$date);
$date=$d[2]."/".$d[1]."/".$d[0];
///////////////
$re=mysql_query("select * from demandes");
while($tab=mysql_fetch_array($re))
{
$h=$tab[10];
}
$sequence=$h + 1;
$ref="REF".$sequence."_".date("dmy");
$sql="INSERT INTO demandes (ref, nom, prenom, fonction, type,assignation,responsable,acteur,date,description)";
$sql.=" VALUES ('$ref', '$nom', '$prenom', '$fonction', '$type', '$assignation', '$responsable', '$acteur','$date', '$description')";
mysql_query("$sql", $connect);
// fermeture de la connection
mysql_close($connect);
echo "<center><h3>L'insertion s'est déroulée avec succés !!!</h3></center>";
?>
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="" method="post" name="frm_demande" id="frm_demande">
<div align="center"></div>
<div align="center">
<table width="60%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td bgcolor="#0000FF"><div align="center"><strong>Formuler Demande </strong></div></td>
</tr>
</table>
</div>
<table width="60%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFCC">
<tr>
<td width="36%"><div align="left"><strong> Référence</strong></div></td>
<td width="64%"><!--input name="ref" type="text" id="ref"-->
<?
echo $ref;
?>
</td>
</tr>
<tr>
<td><strong>Nom</strong></td>
<td><input name="nom" type="text" id="nom"></td>
</tr>
<tr>
<td><strong>Prénom</strong></td>
<td><input name="prenom" type="text" id="prenom"></td>
</tr>
<tr>
<td><strong>Fonction</strong></td>
<td><input name="fonction" type="text" id="fonction"></td>
</tr>
<tr>
<td><strong>Type Demande </strong></td>
<td><select name="type" id="type">
<option>Selectionnez</option>
<option>Incident Technique</option>
<option>Info et Télécom</option>
<option>Demande d'achats</option>
<option>Demande de congé</option>
<option>Demande d'autorisation d'abscence</option>
<option>Demande de vehicule(sans/et chauffeur)</option>
<option>Demande de formation</option>
<option>Demande de prêt interne</option>
<option>Demande de paiement fournisseur</option>
<option>Remboursement</option>
</select></td>
</tr>
<tr>
<td><strong>Assignation Demande </strong></td>
<td><input name="assignation" type="text" id="assignation"></td>
</tr>
<tr>
<td><strong>Responsable Demande </strong></td>
<td><input name="responsable" type="text" id="responsable"></td>
</tr>
<tr>
<td><strong>Acteur</strong></td>
<td><select name="acteur" id="acteur">
<option>Selectionnez</option>
<option>interne</option>
<option>externe</option>
</select></td>
</tr>
<tr>
<td><strong>Date Demande </strong></td>
<td><input name="date" type="text" id="date"></td>
</tr>
<tr>
<td><strong>Description Demande</strong></td>
<td><textarea name="description" id="description"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" id="submit" value="Envoyer">
<input name="submit2" type="reset" id="submit2" value="ANNULER"></td></tr>
</table>
<div align="left"></div>
</form>
</body>
</html> |