Advertisement
Chamtaro

Untitled

Apr 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <title>Mon blog</title>
  6.         <link href="style.css" rel="stylesheet" />
  7.         <?php
  8.         $host='localhost:8889';
  9.         $user='root';
  10.         $pass='root';
  11.         $db = 'Ebay';
  12.         $connect=mysqli_connect($host,$user,$pass);
  13.         $db_select=mysqli_select_db($connect,$db);
  14.         ?>
  15.     </head>
  16.     <body>
  17.         <?php
  18.         header("Location: index.php");
  19.         if(isset($_POST['add'])){
  20.             $mal_rempli=1;
  21.             if(empty($_POST['titre'])){echo "Pas de titre <br>";$mal_rempli=0;}
  22.             if(empty($_POST['prix'])){echo "Pas de prix <br>";$mal_rempli=0;}
  23.             if(empty($_POST['nom'])){echo "Pas de nom <br>";$mal_rempli=0;}
  24.             if(empty($_POST['codepostal'])){echo "Pas de code postal <br>";$mal_rempli=0;}
  25.             if(empty($_POST['mail'])){echo "Pas de mail <br>";$mal_rempli=0;}
  26.             if(empty($_POST['numero'])){echo "Pas de numero <br>";$mal_rempli=0;}
  27.             if(empty($_POST['contenu'])){echo "Pas de contenu <br>";$mal_rempli=0;}
  28.             if($mal_rempli==1){
  29.                 $titre=$_POST['titre'];
  30.                 $date=$_POST['date'];
  31.                 echo "La date :".$date;
  32.                 $prix=$_POST['prix'];
  33.                 $nom=$_POST['nom'];
  34.                 $codepostal=$_POST['codepostal'];
  35.                 $mail=$_POST['mail'];
  36.                 $numero=$_POST['numero'];
  37.                 $affnum=$_POST['affNum'];
  38.                 $contenu=$_POST['contenu'];
  39.                 if(!empty($_POST['image1'])){$image1=$_POST['image1'];}else{$image1='NULL';}
  40.                 if(!empty($_POST['image2'])){$image1=$_POST['image2'];}else{$image2='NULL';}
  41.                 if(!empty($_POST['image3'])){$image1=$_POST['image3'];}else{$image3='NULL';}
  42.                 $nb_id = count(mysqli_fetch_array(mysqli_query($connect,'SELECT id FROM Annonces'))) +1;
  43.                 $request = "INSERT INTO `Annonces` (`id`, `nom`, `titre`, `date`, `codepostal`, `contenu`, `numero`, `affnum`, `mail`, `image1`, `image2`, `image3`) VALUES ('".$nb_id."', '".$nom."', '".$titre."', '".$date."', '".$codepostal."', '".$contenu."', '".$numero."', '".$affnum."', '".$mail."', '".$image1."', ".$image2.", ".$image3.");";
  44.                 echo $request;
  45.                 if(mysqli_query($connect,$request)){
  46.                     //$message='Annonce ajouté !';
  47.                     //echo '<script type="text/javascript">window.alert("'.$message.'");</script>';
  48.                     // Plus tard, faire la redirection.
  49.  
  50.                 }
  51.  
  52.             }else{
  53.                 $Refaire=0;
  54.             }
  55.         }elseif((!isset($_POST['add']))||($Refaire=0)){
  56.         ?>
  57.         <form method="post" action="./new.php">
  58.             <pre>
  59.             Titre   &rarr;  <input type="text" name="titre" size="20">
  60.             Prix    &rarr;  <input type="number_format" name="prix" size="4">
  61.             <input type="hidden" name="date" value="<?php echo date('d-m-Y');?>">
  62.             Nom     &rarr;  <input type="text" name="nom" size="20">
  63.             CP      &rarr;  <input type="number_format" name="codepostal" size="5">
  64.             Email   &rarr;  <input type="email" name="mail">
  65.             Numero  &rarr;  <input type="number_format" name="numero" size="10">
  66.             <br>
  67.             Afficher le numero :
  68.             <input type=radio name="affNum" value="Oui" checked>  Oui
  69.             <input type=radio name="affNum" value="Non">  Non
  70.             <br>
  71.             Saisisez du texte &rarr;
  72.             <textarea name="contenu" rows=10 cols=30></textarea>
  73.             Image 1 &rarr; Lien : <input type="text" name="image1" size=30> <b>ou</b> Fichier :<input type="file" name=image1>
  74.             Image 2 &rarr; Lien : <input type="text" name="image2" size=30> <b>ou</b> Fichier :<input type="file" name=image2>
  75.             Image 3 &rarr; Lien : <input type="text" name="image3" size=30> <b>ou</b> Fichier :<input type="file" name=image3>
  76.             <br>
  77.             <input type="submit" name="add" value="Publier">
  78.             </pre>
  79.         </form>
  80.         <?php
  81.         }
  82.         ?>
  83.     </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement