Advertisement
noam76

insert_appart.php

May 11th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2.     $conn = mysqli_connect("localhost", "root", "", "appartements");
  3.     if(!$conn){
  4.         die("Erreur de connexion à la base de données.");
  5.     }
  6.  
  7.     $numero_appartement = $_POST["numero_appartement"];
  8.     $nom_locataire = $_POST["nom_locataire"];
  9.     $prenom_locataire = $_POST["prenom_locataire"];
  10.  
  11.     $query = "SELECT * FROM appartement WHERE numero_appartement = '$numero_appartement'";
  12.     $result = mysqli_query($conn, $query);
  13.     if(mysqli_num_rows($result) > 0){
  14.         echo "existe";
  15.     }
  16.     else{
  17.         $query = "INSERT INTO appartement (numero_appartement, nom_locataire, prenom_locataire) VALUES ('$numero_appartement', '$nom_locataire', '$prenom_locataire')";
  18.         if(mysqli_query($conn, $query)){
  19.             echo "succes";
  20.         }
  21.         else{
  22.             echo "erreur";
  23.         }
  24.     }
  25.  
  26.     mysqli_close($conn);
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement