Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
<?php
class Baza {
private $mysqli; //uchwyt do BD
public function __construct($serwer, $user, $pass, $baza) {
$this->mysqli = new mysqli($serwer, $user, $pass, $baza);
/* sprawdz połączenie */
if ($this->mysqli->connect_errno) {
printf("Nie udało sie połączenie z serwerem: %sn",
$this->mysqli->connect_error);
exit();
}
/* zmien kodowanie na utf8 */
if ($this->mysqli->set_charset("utf8")) {
//udało sie zmienić kodowanie
}
} //koniec funkcji konstruktora
function __destruct() {
$this->mysqli->close();
}
public function select($sql, $pola) {
//parametr $sql – łańcuch zapytania select
//parametr $pola - tablica z nazwami pol w bazie
//Wynik funkcji – kod HTML tabeli z rekordami (String)
$tresc = "";
if ($result = $this->mysqli->query($sql)) {
$ilepol = count($pola); //ile pól
$ile = $result->num_rows; //ile wierszy
// pętla po wyniku zapytania $results
$tresc.="<table><tbody>";
while ($row = $result->fetch_object()) {
$tresc.="<tr>";
for ($i = 0; $i < $ilepol; $i++) {
$p = $pola[$i];
$tresc.="<td>" . $row->$p . "</td>";
}
$tresc.="</tr>";
}
$tresc.="</table></tbody>";
$result->close(); /* zwolnij pamięć */
}
return $tresc;
}
public function insert($sql) {
return $this->mysqli->query($sql);
}
}
?>
funkcje
<?php
$tech = ["PHP","Java","CPP"];
function drukuj_form(){
echo "<!DOCTYPE html>
<html>
<head>
<title>Aplikacja bazodanowa</title>
<meta charset='UTF-8'>
</head>
<body>
<form method='get' action=''>
Nazwisko:
<input type='text' name='nazw'><br>
Wiek:
<input type='text' name='wiek'><br>
<select name='panstwo'>
<option>Polska</option>
<option>Czechy</option>
<option>Niemcy</option>
<option>Wielka Brytania</option>
</select><br>
Email:
<input type ='text' name='email'><br>
Zamawiam tutoriale z języka:<br>
";
global $tech;
foreach ($tech as $value)
echo "<input type='checkbox' name='tech[]' value=$value>$value";
echo "<br>Sposób zapłaty:<br>
<input type='radio' name='zaplata' value='eurocard'>eurocard
<input type='radio' name='zaplata' value='visa'>visa
<input type='radio' name='zaplata' value='przelew'>przelew bankowy<br>
<input type='submit' name='submit' value='Dodaj'>
<input type='submit' name='submit' value='Pokaż'>
<input type='submit' name='submit' value='PHP'>
<input type='submit' name='submit' value='Java'>
<input type='submit' name='submit' value='CPP'>
</br></br>
ID:<input type='submit' name='usunid'><input type='submit' name='submit' value='Usuń'><br>";
}
function walidacja($bd)
{
$args=[
'nazwa'=>FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'wiek'=>FILTER_VALIDATE_INT,
'panstwo'=>FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'email'=>FILTER_VALIDATE_EMAIL,
'tech'=>['filter'=>FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'flags'=>FILTER_REQUIRE_ARRAY
],
'zaplata'=>FILTER_SANITIZE_FULL_SPECIAL_CHARS,
];
$dane= filter_input_array(INPUT_GET,$args);
$errors="";
foreach($dane as $key => $val)
if($val===false or $val===NULL)
$errors.=$key." ";
if($errors===" ")
dodajdoBD ($bd,$dane);
else
echo "<br>Nieprawidłowe dane: ".$errors;
}
function dodajdoBD($bd){
//pobierz dane z formularza, dokonaj ich walidacji
//sformułuj zapytanie $sql typu insert np.:
$sql="INSERT INTO klienci VALUES (NULL, 'Babacka', '22', 'Niemcy','[email protected]', 'Java,CPP', 'Przelew')";
$bd->insert($sql);
}
?>
index
<?php
include_once("funkcje.php");
drukuj_form();
include_once "baza.php";
//tworzymy uchwyt do bazy danych:
$bd = new Baza("localhost", "root", "", "klienci");
if (filter_input(INPUT_GET, "submit")) {
$akcja = filter_input(INPUT_GET, "submit");
switch ($akcja) {
case "Dodaj" : dodajdoBD($bd); break;
case "Pokaż" : echo $bd->select("select Nazwisko,Zamowienie from klienci",
array("Nazwisko","Zamowienie")); break;
}
}
?>
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team