Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. pdoform.php:
  2. <!doctype html>
  3. <html>
  4. <head>
  5. <title>pdo</title>
  6. <meta charset="utf-8" />
  7. </head>
  8. <body>
  9. <form action="wynik1pdo.php" method="post">
  10. id: <input type="text" name="id"><br>
  11. imie: <input type="text" name="imie"><br>
  12. nazwisko:<input type="text" name="nazwisko"><br>
  13. pesel:<input type="text" name="pesel"><br>
  14. klasa <input type="text" name="klasa"><br>
  15.  
  16.  
  17. <input type="submit" value="Wyślij">
  18. </form>
  19.  
  20.  
  21. </body>
  22. </html>
  23.  
  24. ................................................................
  25. wynik1pdo.php:
  26. <!doctype html>
  27. <html>
  28. <head>
  29. <title>pdo</title>
  30. <meta charset="utf-8" />
  31. </head>
  32. <body>
  33. <?php
  34. //dla bazy w Mysql
  35.  
  36.  
  37. try
  38. {
  39. $db = new PDO('mysql:host=localhost;dbname=szkola', 'root', '');
  40. }
  41. catch (PDOException $e)
  42. {
  43. print "Błąd połączenia z bazą!: " . $e->getMessage() . "<br/>";
  44. die();
  45. }
  46.  
  47. $statement = $db->prepare('insert into uczen values (:id,:imie,:nazwisko,:pesel,:klasa)');
  48. $statement->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
  49. $statement->bindValue(':imie', $_POST['imie'], PDO::PARAM_INT);
  50. $statement->bindValue(':nazwisko', $_POST['nazwisko'], PDO::PARAM_INT);
  51. $statement->bindValue(':pesel', $_POST['pesel'], PDO::PARAM_INT);
  52. $statement->bindValue(':klasa', $_POST['klasa'], PDO::PARAM_INT);
  53. $wynik=$statement->execute();
  54.  
  55. if($wynik){
  56. echo 'dodano!<br>';
  57. }
  58. $zapytanie = $db->query('SELECT * FROM uczen');
  59. foreach($zapytanie as $wiersz)
  60. {
  61. echo($wiersz['id']." ".$wiersz['imie']." ".$wiersz['nazwisko']." ".$wiersz['PESEL']." ".$wiersz['klasa']."<br />");
  62. }
  63. $zapytanie->closeCursor();
  64.  
  65. ?>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement