par
dunbar » 27 nov. 2006, 03:19
Poste ton code actuel
Voici
function corps() {
if ($_GET['action'] == 'add') {
$rights = "0777";
$type = $_POST['type'];
$prix = $_POST['prix'];
$codepostal = $_POST['codepostal'];
$chambres = $_POST['chambre'];
$garages = $_POST['garage'];
$photo = $_POST['photo'];
//==========================================================
//
// Connexion à la base
//===========================================================
$connection = mysqli_connect("") or die(mysqli_error());
mysqli_select_db($connection, "");
$req = "select max(id_annonce) from annonce;";
$res = mysqli_query($connection, $req) or die(mysqli_error());
$id = 0;
while ($row = mysqli_fetch_row($res)){
$id = $row[0]++;
}
if ($id == null){
$id = 0;
}
$folder_path = 'clients/'.$id;
if(!@mkdir($folder_path, $rights)){
echo("Impossible de créer le dossier "$folder_path".");
exit(0);
}
echo $req = "INSERT INTO directory (name) VALUES ('".$folder_path."')";
$res = mysqli_query($connection, $req) or die("Impossible de se connecter à la base(1) : ".mysqli_error());
echo $req = "INSERT INTO annonce (id_directory, type, prix, codepostal, nb_chambre, nb_garage, nb_file) VALUES ('".$id."', '".$type."', '".
$prix."', '".$codepostal."', '".$chambres."', '".$garages."', '".$photo."');";
$res = mysqli_query($connection, $req) or die("Impossible de se connecter à la base(2) : ".mysqli_error());
if ($photo > 0){
$i = 0;
while ($i < $photo){
$i++;
$name = 'file'.$i;
$tmp_file = $_FILES['$name']['tmp_name'];
if( !is_uploaded_file($tmp_file) )
{
echo("Le fichier est introuvable");
exit(0);
}
// on vérifie maintenant l'extension
$type_file = $_FILES['$name']['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'bmp') && !strstr($type_file, 'gif') )
{
echo("Le fichier n'est pas une image");
exit(0);
}
// on copie le fichier dans le dossier de destination
$name_file = $_FILES['$name']['name'];
if( !move_uploaded_file($tmp_file, $folder_path . $name_file) )
{
echo("Impossible de copier le fichier dans $content_dir");
exit(0);
}
$req = "insert into file (id_directory, name) values ('".$id."', '".$name_file."');";
$res = mysqli_query($connection, $req) or die(mysqli_error());
}
}
}
echo '<form action="createAnnonce.php?action=add" method="post" enctype="multipart/form-data" ><center> </p>';
echo '<table border=0 cellspacing=10><tr><td class="corps">Type de bien * :</td><td><SELECT NAME="type"><OPTION>Maison
<OPTION>Appartement
<OPTION>Terrain
</SELECT></td></tr>';
echo '<tr><td class="corps">Prix * :</td><td><INPUT TYPE="text" name="prix" maxlength="10"></td></tr>';
echo '<tr><td class="corps">Code Postal * :</td><td><INPUT TYPE="text" name="codepostal" maxlength="5"></td></tr>';
echo '<tr><td class="corps">Nbre Chambres * :</td><td><SELECT NAME="chambre"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Nbre Garage * :</td><td><SELECT NAME="garage"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Commentaire Sur le bien * :</td>';
echo '<td class="corps"><textarea name="commentaire" cols=34 rows=4></textarea></td></tr>';
echo '<tr><td class="corps">Nbre Photos * :</td><td><SELECT NAME="photo"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Fichier 1 :</td><td><INPUT TYPE="file" name="file1"></td></tr>';
echo '<tr><td class="corps">Fichier 2 :</td><td><INPUT TYPE="file" name="file2"></td></tr>';
echo '<tr><td class="corps">Fichier 3 :</td><td><INPUT TYPE="file" name="file3"></td></tr>';
echo '<tr><td class="corps">Fichier 4 :</td><td><INPUT TYPE="file" name="file4"></td></tr>';
echo '<tr><td class="corps">Fichier 5 :</td><td><INPUT TYPE="file" name="file5"></td></tr>';
echo '<tr><td colspan=2 align=center><INPUT TYPE="submit" VALUE="Enregistrer l\'annonce"><INPUT TYPE=reset NAME=Effacer VALUE="Effacer le formulaire" ></td></tr><br><br>';
echo "<tr><td colspan=2 align=center class='corps'>Les champs marqué d'une * sont obligatoires</td></tr></table></center></form><br><br>";
}
?>
[quote="Ajoloca"]Poste ton code actuel[/quote]
Voici
[php]function corps() {
if ($_GET['action'] == 'add') {
$rights = "0777";
$type = $_POST['type'];
$prix = $_POST['prix'];
$codepostal = $_POST['codepostal'];
$chambres = $_POST['chambre'];
$garages = $_POST['garage'];
$photo = $_POST['photo'];
//==========================================================
//
// Connexion à la base
//===========================================================
$connection = mysqli_connect("") or die(mysqli_error());
mysqli_select_db($connection, "");
$req = "select max(id_annonce) from annonce;";
$res = mysqli_query($connection, $req) or die(mysqli_error());
$id = 0;
while ($row = mysqli_fetch_row($res)){
$id = $row[0]++;
}
if ($id == null){
$id = 0;
}
$folder_path = 'clients/'.$id;
if(!@mkdir($folder_path, $rights)){
echo("Impossible de créer le dossier "$folder_path".");
exit(0);
}
echo $req = "INSERT INTO directory (name) VALUES ('".$folder_path."')";
$res = mysqli_query($connection, $req) or die("Impossible de se connecter à la base(1) : ".mysqli_error());
echo $req = "INSERT INTO annonce (id_directory, type, prix, codepostal, nb_chambre, nb_garage, nb_file) VALUES ('".$id."', '".$type."', '".
$prix."', '".$codepostal."', '".$chambres."', '".$garages."', '".$photo."');";
$res = mysqli_query($connection, $req) or die("Impossible de se connecter à la base(2) : ".mysqli_error());
if ($photo > 0){
$i = 0;
while ($i < $photo){
$i++;
$name = 'file'.$i;
$tmp_file = $_FILES['$name']['tmp_name'];
if( !is_uploaded_file($tmp_file) )
{
echo("Le fichier est introuvable");
exit(0);
}
// on vérifie maintenant l'extension
$type_file = $_FILES['$name']['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'bmp') && !strstr($type_file, 'gif') )
{
echo("Le fichier n'est pas une image");
exit(0);
}
// on copie le fichier dans le dossier de destination
$name_file = $_FILES['$name']['name'];
if( !move_uploaded_file($tmp_file, $folder_path . $name_file) )
{
echo("Impossible de copier le fichier dans $content_dir");
exit(0);
}
$req = "insert into file (id_directory, name) values ('".$id."', '".$name_file."');";
$res = mysqli_query($connection, $req) or die(mysqli_error());
}
}
}
echo '<form action="createAnnonce.php?action=add" method="post" enctype="multipart/form-data" ><center> </p>';
echo '<table border=0 cellspacing=10><tr><td class="corps">Type de bien * :</td><td><SELECT NAME="type"><OPTION>Maison
<OPTION>Appartement
<OPTION>Terrain
</SELECT></td></tr>';
echo '<tr><td class="corps">Prix * :</td><td><INPUT TYPE="text" name="prix" maxlength="10"></td></tr>';
echo '<tr><td class="corps">Code Postal * :</td><td><INPUT TYPE="text" name="codepostal" maxlength="5"></td></tr>';
echo '<tr><td class="corps">Nbre Chambres * :</td><td><SELECT NAME="chambre"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Nbre Garage * :</td><td><SELECT NAME="garage"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Commentaire Sur le bien * :</td>';
echo '<td class="corps"><textarea name="commentaire" cols=34 rows=4></textarea></td></tr>';
echo '<tr><td class="corps">Nbre Photos * :</td><td><SELECT NAME="photo"><OPTION>0
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT></td></tr>';
echo '<tr><td class="corps">Fichier 1 :</td><td><INPUT TYPE="file" name="file1"></td></tr>';
echo '<tr><td class="corps">Fichier 2 :</td><td><INPUT TYPE="file" name="file2"></td></tr>';
echo '<tr><td class="corps">Fichier 3 :</td><td><INPUT TYPE="file" name="file3"></td></tr>';
echo '<tr><td class="corps">Fichier 4 :</td><td><INPUT TYPE="file" name="file4"></td></tr>';
echo '<tr><td class="corps">Fichier 5 :</td><td><INPUT TYPE="file" name="file5"></td></tr>';
echo '<tr><td colspan=2 align=center><INPUT TYPE="submit" VALUE="Enregistrer l\'annonce"><INPUT TYPE=reset NAME=Effacer VALUE="Effacer le formulaire" ></td></tr><br><br>';
echo "<tr><td colspan=2 align=center class='corps'>Les champs marqué d'une * sont obligatoires</td></tr></table></center></form><br><br>";
}
?>[/php]