Last active
April 21, 2016 11:38
-
-
Save Harvie/f7768e40110372dbfd129d68d0e429d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="POST" action="index.php"> | |
Jméno: | |
<input type="text" size=16 name="jmeno"> | |
Poíjmení: | |
<input type="text" size=16 name="prijmeni"> | |
E-mail: | |
<input type="text" size=16 name="email"> | |
Telefon: | |
<input type="text" size=16 name="telefon"> | |
<input type="submit" value="odeslat"> | |
</form> | |
<?php | |
//pripojeni DB | |
$dbh = new PDO('mysql:host=localhost;dbname=ete32e_1516zs_04', 'ete32e_1516zs_04', 'poiu4567'); | |
// pridej 'heslo' | |
if(!isset($_POST['jmeno'])) { | |
echo('vypln formular'); | |
} else { | |
//promenne | |
$jmeno = trim($_POST['jmeno']); | |
$prijmeni = trim($_POST['prijmeni']); | |
$email = trim($_POST['email']); | |
$telefon = trim($_POST['telefon']); | |
//kontrola | |
if (!preg_match("/^[a-zA-Z]*$/",$jmeno)) die('Zadane jmeno je neplatne.'); | |
if (!preg_match("/^[a-zA-Z]*$/",$prijmeni)) die('Zadane prijmeni je neplatne.'); | |
if (!preg_match("/^[a-zA-Z0-9\.-]*@[a-zA-Z0-9\.-]*$/",$email)) die('Zadany email je neplatny.'); | |
if (!preg_match("/^[0-9]{9}$/",$telefon)) die('Zadany telefon je neplatny.'); | |
//zalozime tabulku | |
$dbh->exec(' | |
CREATE TABLE IF NOT EXISTS tabulkaformular ( | |
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, | |
jmeno VARCHAR(128), | |
prijmeni VARCHAR(128), | |
email VARCHAR(128), | |
telefon VARCHAR(128) | |
) | |
'); | |
//this insert statement works: | |
$dbh->exec("INSERT INTO jmenotabulky(jmeno, prijmeni, email, telefon) VALUES ('$jmeno', '$prijmeni', '$email','$telefon')"); | |
} | |
$result = $dbh->query("SELECT * FROM jmenotabulky")->fetchAll(PDO::FETCH_ASSOC); | |
//vypis vysledky | |
echo('<hr /><pre>'); | |
print_r($result); | |
echo('</pre>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment