Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pdoform.php:
- <!doctype html>
- <html>
- <head>
- <title>pdo</title>
- <meta charset="utf-8" />
- </head>
- <body>
- <form action="wynik1pdo.php" method="post">
- id: <input type="text" name="id"><br>
- imie: <input type="text" name="imie"><br>
- nazwisko:<input type="text" name="nazwisko"><br>
- pesel:<input type="text" name="pesel"><br>
- klasa <input type="text" name="klasa"><br>
- <input type="submit" value="Wyślij">
- </form>
- </body>
- </html>
- ................................................................
- wynik1pdo.php:
- <!doctype html>
- <html>
- <head>
- <title>pdo</title>
- <meta charset="utf-8" />
- </head>
- <body>
- <?php
- //dla bazy w Mysql
- try
- {
- $db = new PDO('mysql:host=localhost;dbname=szkola', 'root', '');
- }
- catch (PDOException $e)
- {
- print "Błąd połączenia z bazą!: " . $e->getMessage() . "<br/>";
- die();
- }
- $statement = $db->prepare('insert into uczen values (:id,:imie,:nazwisko,:pesel,:klasa)');
- $statement->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
- $statement->bindValue(':imie', $_POST['imie'], PDO::PARAM_INT);
- $statement->bindValue(':nazwisko', $_POST['nazwisko'], PDO::PARAM_INT);
- $statement->bindValue(':pesel', $_POST['pesel'], PDO::PARAM_INT);
- $statement->bindValue(':klasa', $_POST['klasa'], PDO::PARAM_INT);
- $wynik=$statement->execute();
- if($wynik){
- echo 'dodano!<br>';
- }
- $zapytanie = $db->query('SELECT * FROM uczen');
- foreach($zapytanie as $wiersz)
- {
- echo($wiersz['id']." ".$wiersz['imie']." ".$wiersz['nazwisko']." ".$wiersz['PESEL']." ".$wiersz['klasa']."<br />");
- }
- $zapytanie->closeCursor();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement