 | | Offres d'emplois |  | developpeur web Vous souhaitez intégrer une équipe dynamique et créative ? Nous recherchons développeur(euse) pour créer des sites internet à Lille. Connaissances ... | |
 | | Avez vous lu ? |  | | |
|
 Utiliser des fonctions de formatage des chaînes de texte | |  |

<?php
/*
Formater des valeurs avant insertion
dans base de données
*/
function form() {
$txt = '<table align="center" width="50%" border="0">';
$txt .= '<form method="post" action="'
. $_SERVER['PHP_SELF'] . '">';
$txt .= '<input type="hidden"
name="action" value="insert_contact">';
$txt .= '<tr>';
$txt .= '<td>Nom :</td>';
$txt .= '<td><input type="text" name="nom"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Prénom :</td>';
$txt .= '<td><input type="text" name="prenom"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Adresse :</td>';
$txt .= '<td><input type="text" name="adresse"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Code postal</td>';
$txt .= '<td><input type="text" name="zipcode"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Ville :</td>';
$txt .= '<td><input type="text" name="ville"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Adresse email :</td>';
$txt .= '<td><input type="text" name="email"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Téléphone :</td>';
$txt .= '<td><input type="text" name="tel"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td>Fax :</td>';
$txt .= '<td><input type="text" name="fax"></td>';
$txt .= '</tr>';
$txt .= '<tr>';
$txt .= '<td colspan="2" align="center">
<input type="submit" name="Submit" value="Envoyer"></td>';
$txt .= '</tr>';
$txt .= '</table>';
$txt .= '</form>';
echo $txt;
}
function insert_contact() {
$nom = str_strip_tags($_POST['nom']);
$prenom =
str_strip_tags($_POST['prenom']);
$adresse =
str_strip_tags($_POST['adresse']);
$zipcode =
ereg_replace("[^0-9]", "", $_POST['zipcode']);
$ville = str_strip_tags($_POST['ville']);
$email = str_strip_tags($_POST['email']);
$tel = ereg_replace("[^0-9]", "",
str_strip_tags($_POST['tel']));
$fax = ereg_replace("[^0-9]", "",
str_strip_tags($_POST['fax']));
$req = "insert into matable(nom, prenom, adresse, zip,
ville, email, tel, fax)
values('";
$req .= str_addslashes($nom) . "', '"
. str_addslashes($prenom) . "', '"
. str_addslashes($adresse) . ", '"
. $zipcode . "', '"
. str_addslashes($ville) . "', '"
. $email . "', '" . $tel . "', '" . $fax . "');";
/*
echo $req;
$result = mysql_query($req);
Traitements....
*/
}
?>
|
|
|
 |
|