query('select id, fullname, birthdate, country_code from person')
->fetch_all(MYSQLI_ASSOC);
// echo format_html_table($person_list, 'persontable');
?>
%s, %s, %s \n",
$person['id'],
$person['fullname'],
$person['birthdate'],
$person['country_code']
);
}
?>
update_person.php
query('select Code, Name from country')
->fetch_all(MYSQLI_ASSOC);
$sth = $dbh->prepare(
'select fullname, birthdate, country_code from person where id = ?'
);
$id = $_GET['id'];
$sth->bind_param("d", $id);
$sth->execute();
$sth->bind_result($fullname, $birthdate, $country_code);
$sth->fetch();
?>
prepare(
"update person
set fullname = ?,
birthdate = ?,
country_code = ?
where id = ?"
);
$fullname = $_POST['fullname'];
$birthdate = $_POST['birthdate'];
$country_code = $_POST['country_code'];
$id = $_POST['id'];
$sth->bind_param("sssd", $fullname, $birthdate, $country_code, $id);
$sth->execute();
}
==== Update oder Insert ====
write_person.php
query('select Code, Name from country')
->fetch_all(MYSQLI_ASSOC);
if (isset($_GET['id'])) {
$id = $_GET['id'];
$sth = $dbh->prepare(
'select fullname, birthdate, country_code from person where id = ?'
);
$sth->bind_param("d", $id);
$sth->execute();
$sth->bind_result($fullname, $birthdate, $country_code);
$sth->fetch();
} else {
$id = '';
$fullname = '';
$birthdate = '';
$country_code = '';
}
?>
\n";
$id = $_POST['id'];
$sth = $dbh->prepare(
"update person
set fullname = ?,
birthdate = ?,
country_code = ?
where id = ?"
);
$sth->bind_param("sssd", $fullname, $birthdate, $country_code, $id);
} else {
echo "inserting
\n";
$sth = $dbh->prepare(
"insert into person
(fullname,
birthdate,
country_code)
values (?, ?, ?)"
);
$sth->bind_param("sss", $fullname, $birthdate, $country_code);
}
$sth->execute();
}
list-persons.php
query('select id, fullname, birthdate, country_code from person')
->fetch_all(MYSQLI_ASSOC);
// echo format_html_table($person_list, 'persontable');
?>
%s, %s, %s \n",
$person['id'],
$person['fullname'],
$person['birthdate'],
$person['country_code']
);
}
?>
Add new person
==== Single Page CRUD ====
noch sehr unansehnlich
";
var_dump($path);
echo "";
*/
if (empty($path)) {
list_persons($dbh);
exit;
}
elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && $path[1] == 'write') {
$country_list =
$dbh->query('select Code, Name from country')
->fetch_all(MYSQLI_ASSOC);
if ($path[2] == 'id' and isset($path[3])) {
$id = $path[3];
echo "Update Person $id
\n";
$sth = $dbh->prepare(
'select id, fullname, birthdate, country_code from person where id = ?'
);
$sth->bind_param("d", $id);
$sth->execute();
$sth->bind_result($read_id, $fullname, $birthdate, $country_code);
$sth->fetch();
if ($read_id != $id) {
?>
unknown id, go away
Insert Person\n";
$id = '';
$fullname = '';
$birthdate = '';
$country_code = '';
}
?>
\n";
$id = $_POST['id'];
$sth = $dbh->prepare(
"update person
set fullname = ?,
birthdate = ?,
country_code = ?
where id = ?"
);
$sth->bind_param("sssd", $fullname, $birthdate, $country_code, $id);
} else {
echo "inserting
\n";
$sth = $dbh->prepare(
"insert into person
(fullname,
birthdate,
country_code)
values (?, ?, ?)"
);
$sth->bind_param("sss", $fullname, $birthdate, $country_code);
}
$sth->execute();
}
function list_persons($dbh) {
$person_list =
$dbh->query('select id, fullname, birthdate, country_code from person')
->fetch_all(MYSQLI_ASSOC);
?>
%s, %s, %s \n",
$person['id'],
$person['fullname'],
$person['birthdate'],
$person['country_code']
);
}
?>
Add new person