非構造化
• 長い
• 読めますか?
• ここに全部ある
= 1) goto end_page_check;
goto set_default_page;
end_page_check:
$totalCount = 0;
$msgs = [];
$result = mysqli_query(
$dbo,
'SELECT COUNT(*) FROM messages',
);
if ($result !== false) goto list_msgs_page;
$totalCount =
(int)mysqli_fetch_column($result);
$limit = 10;
$offset = ($page - 1) * $limit;
$stmt = mysqli_prepare(
$dbo,
'SELECT * FROM messages ORDER BY id DESC
LIMIT ? OFFSET ?'
);
mysqli_stmt_bind_param($stmt, 'ii', $limit,
$offset);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$msgs = mysqli_fetch_all($result,
MYSQLI_ASSOC);
$msgCnt = count($msgs);
$totalPage = ceil($totalCount / 10);
list_msgs_page:
?>
ݴҰཡ
=
htmlspecialchars($message['title']) ?>
title>
ߘऀ
=
htmlspecialchars($message['author']) ?>
ߘ
=
$message['created_at'] ?>
=
nl2br(htmlspecialchars($message['body'])) ?>
৽نݴ࡞
=
$errorCount) goto error_list_end;
$errorField =
array_keys($errors)[$i];
?>
- =
$errors[$errorField] ?>
:
ొ
button>
filter_input(INPUT_POST,
'title'),
'author' => filter_input(INPUT_POST,
'author'),
'body' => filter_input(INPUT_POST,
'body'),
];
$errors = [];
validate_title:
if ($postMessage['title'] &&
mb_strlen($postMessage['title']) <= 50) goto
validate_author;
$errors['title'] = 'λΠτϧ50จࣈҎͰೖྗ͠
͍ͯͩ͘͞';
validate_author:
if ($postMessage['author'] &&
mb_strlen($postMessage['author']) <= 50) goto
validate_body;
$errors['author'] = 'ߘऀ໊50จࣈҎͰೖྗ͠
͍ͯͩ͘͞';
validate_body:
if ($postMessage['body'] &&
mb_strlen($postMessage['body']) <= 500) goto
validate_end;
$errors['body'] = 'ຊจ500จࣈҎͰೖྗͯ͘͠
͍ͩ͞';
validate_end:
if ($errors) goto new_message;
$postMessage['created_at'] = date('Y-m-d
H:i:s');
$stmt = mysqli_prepare($dbo, 'INSERT INTO
`msgs` (`title`, `author`, `body`,
`created_at`) VALUES (?, ?, ?, ?)');
mysqli_stmt_bind_param($stmt, 'ssss',
$postMessage['title'],
$postMessage['author'], $postMessage['body'],
$postMessage['created_at']);
mysqli_stmt_execute($stmt);
if (mysqli_stmt_error($stmt)) goto end;
$id = mysqli_stmt_insert_id($stmt);
header("Location: /?action=detail&id={$id}");
goto end;
/* ΤϥʔϋϯυϦϯά */
db_error:
echo "σʔλϕʔεଓΤϥʔ", PHP_EOL;
goto end;
redirect_home:
header("Location: /");
goto end;
redirect_new:
header("Location: /?action=new");
goto end;
end:
goto program_exit;
/* ϓϩάϥϜऴྃ */
program_exit: