Guest User

php

a guest
Mar 31st, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <html>
  2. <head>
  3.    
  4.    
  5.     </head>
  6. <body>
  7.     <form action="pdo.php" method="post">
  8.        
  9.     <input type="text" name="id">
  10.         <input type="text" name="tytul2">
  11.         <input type="text" name="autor2">
  12.         <button type="submit" name="button">Zapisz</button>
  13.            
  14.     </form>
  15.        
  16.     <?php
  17.     if(!empty($_POST["wyrazenie"]))
  18.        {
  19.     $servername="localhost";
  20.     $username="admin2";
  21.     $password="";
  22.     $wyrazenie=$_POST["wyrazenie"];
  23.        
  24.         $tytul=$_POST["tytul2"];
  25.         $autor=$_POST["autor2"];
  26.     $pdo = new PDO("mysql:host=$servername;dbname=cwiczenia",$username,$password);
  27.    
  28.    
  29.    // $delete="delete from ksiazki where id='".$wyrazenie."'";
  30.     $insert="INSERT INTO ksiazki (id,tytul,autor)values('','$tytul','$autor')";
  31.        // $pdo->query($delete);
  32.         $pdo->exec($insert);
  33.         echo "Rekord zostal dodany";
  34.        
  35.          $select='select * from ksiazki';
  36.     $wynik=$pdo->query($select);
  37.     foreach($wynik as $row)
  38.         echo $row["id"].' '.$row["tytul"].' '.$row["autor"]."<br>";
  39.    
  40.        }
  41.    
  42.     ?>
  43.    
  44.    
  45.     </body>
  46.  
  47.  
  48. </html>
Add Comment
Please, Sign In to add comment