Advertisement
amine99

Untitled

Sep 10th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. //Exercice 3
  2. <?php
  3. /*(1)*/
  4.     $con = mysqli_connect("localhost", "root", "","testBD");
  5.  
  6. /*(2)*/
  7.     $req = "SELECT * FROM Client ORDERED BY nom";
  8.     $res = mysqli_query($con, $req);
  9.     while($row = mysqli_fetch_array($res))
  10.         echo "$row[0] $row[1] $row[2] $row[3] <br>";
  11.    
  12. /*(3)*/
  13.     $req = "SELECT * FROM Produit WHERE QStocke <= 50";
  14.     mysqli_query($con, $res);
  15.     echo "<html>
  16.             <script>alert($mysqli_affected_rows($con))</script>
  17.           </html>";
  18.  
  19. /*(4)*/
  20.     $stmt = $dbh->prepare("INSERT INTO Produit VALUES(?, ?, ?, ?)");
  21.     $stmt = bindParam(1,$nump);
  22.     $stmt = bindParam(2,$nomp);
  23.     $stmt = bindParam(3,$prix);
  24.     $stmt = bindParam(4,$qte);
  25.    
  26.     $nump = 1;
  27.     $nomp = "prod 1";
  28.     $prix = 100;
  29.     $qte = 50;
  30.     $stmt->execute();
  31.    
  32.     $nump = 2;
  33.     $nomp = "prod 2";
  34.     $prix = 250;
  35.     $qte = 33;
  36.     $stmt->execute();
  37.    
  38. /*(5)*/
  39.     $req = "INSERT INTO Produit VALUES(1, 'prod 1', 100, 50);INSERT INTO Produit VALUES(2, 'prod 2', 250, 33)";
  40.     mysqli_multi_query($con, $req);
  41.    
  42. /*(6)*/
  43.     echo "<html>
  44.             <body>
  45.                 <form methode = 'post' action = 'aff.php'>
  46.                     <input type = 'text' name = 'num'>
  47.                     <input type = 'submit' value = 'Rechercher'>
  48.                 </form>
  49.             </body>
  50.           </html>";
  51. ?>
  52.  
  53. //aff.php
  54. <?php
  55.     $num = $_POST["num"];
  56.     $con = mysqli_connect("localhost", "root", "","testBD");
  57.     $req = "SELECT NumP, NomP, Qte FROM Produit p, Commande c, Ligne_commande c where $num = l.numCmd and $num = c.numCmd and p.numP = l.NumP";
  58.     $res = mysqli_query($con, $req);
  59.     while($row = mysqli_fetch_array($con, $res)) {
  60.         echo "<html>
  61.                 <body>
  62.                     <table>
  63.                         <tr>
  64.                             <td>$row[0]</td>
  65.                             <td>$row[1]</td>
  66.                             <td>$row[2]</td>
  67.                         </tr>";
  68.     }
  69.     echo "</table> </body> </html>";
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement