<?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>
ID:<input type='text' size='3' name='usunid'><input type='submit' name='submit' value='Usuń'><br>";
}
function walidacja($bd){
$args=[
'nazw'=>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>Nieprawidlowe dane: ".$errors;
}
function dodajdoBD($bd, $d){
//$sql="INSERT INTO klienci VALUES (NULL, 'Babacka', '22', 'Niemcy', '
[email protected]', 'Java,CPP', 'Przelew')";
$sql="INSERT INTO klienci VALUES (NULL,'".$d['nazw'].",".$d['wiek'].",".$d['panstwo'].",".$d['email'].",".$d['tech'].",".$d['zaplata'].")";
$bd->insert($sql);
}
?>