<?php $max_posts_page = 3; $count_post = 30; $page_get = $_GET['p'] ?? '1'; $page_end = $page_get * $max_posts_page; $page_first = $page_end - $max_posts_page; $max_pages = ceil($count_post / $max_posts_page); $max_pages = ( $max_pages == 0 ) ? 1 : $max_pages; $this_page = basename(__FILE__); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>ページネーション</title> <link rel="icon" href="favicon.svg" type="image/svg+xml"> <style> .pagination { margin-top: 2em; text-align: center; font-size: 12px; } .pagination a, .pagination span { display: inline-block; margin: 4px 2px; text-decoration: none; border-radius: 4px; width: 30px; height: 30px; padding: 7px 0; box-sizing: border-box; color: #000; border: 2px solid #000; font-weight: bold; line-height: 1; } .pagination a:hover { color: #000; opacity: 0.7; } .pagination .page-current { border: none; background: transparent; } .prev-x, .next-x { cursor: no-drop; } </style> </head> <body> <div class="pagination"> <div class="nav-links"> <?php if ($page_get == "1"): ?> <span id="prev-x" class="prev-x page-numbers">‹</span> <?php else: ?> <a id="prev" class="prev page-numbers" href="./<?php echo $this_page ; ?>?p=<?php echo $page_get - 1; ?>">‹</a> <?php endif; ?> <?php if ($page_get != "1"): ?> <a id="first" class="first page-numbers" href="./<?php echo $this_page ; ?>?p=1">1</a> <?php endif; ?> <?php if ($page_get >= "5"): ?> <span id="dots_left" class="page-numbers dots">…</span> <?php endif; ?> <?php for ($i = max(2, $page_get - 2); $i < $page_get; $i++): ?> <a id="page-numbers<?php echo $i; ?>" class="page-numbers" href="./<?php echo $this_page ; ?>?p=<?php echo $i; ?>"><?php echo $i; ?></a> <?php endfor; ?> <span aria-current="page" class="page-numbers page-current"><?php echo $page_get; ?></span> <?php for ($i = $page_get + 1; $i <= min($page_get + 2, $max_pages - 1); $i++): ?> <a id="page-numbers<?php echo $i; ?>" class="page-numbers" href="./<?php echo $this_page ; ?>?p=<?php echo $i; ?>"><?php echo $i; ?></a> <?php endfor; ?> <?php if ($max_pages - $page_get >= "4"): ?> <span id="dots_right" class="page-numbers dots">…</span> <?php endif; ?> <?php if ($page_get != $max_pages): ?> <a id="last" class="last page-numbers" href="./<?php echo $this_page ; ?>?p=<?php echo $max_pages; ?>"><?php echo $max_pages; ?></a> <?php endif; ?> <?php if ($page_get == $max_pages): ?> <span id="next-x" class="next-x page-numbers">›</span> <?php else: ?> <a id="next" class="next page-numbers" href="./<?php echo $this_page ; ?>?p=<?php echo $page_get + 1; ?>">›</a> <?php endif; ?> </div> </div> </body> </html>
<form id="myForm" method="post"> <div> <label for="pref">都道府県</label> <select id="pref" name="pref"> <option value="01">北海道</option> <option value="02" selected>青森県</option> <option value="03">岩手県</option> </select> </div> <div> <label for="comment">コメント</label> <textarea id="comment" name="comment" required></textarea> </div> <div> <button type="submit">登録</button> </div> </form>
document.getElementById('myForm').addEventListener('submit', function(event) { event.preventDefault(); // デフォルトのフォーム送信を防ぐ var pref = document.getElementById('pref').value; var comment = document.getElementById('comment').value; fetch('submit.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'pref=' + encodeURIComponent(pref) + '&comment=' + encodeURIComponent(comment) }) .then(response => response.text()) .then(data => { alert('データが正常に送信されました'); }) .catch(error => { console.error('エラーが発生しました:', error); }); });
submit.php
<?php $servername = "localhost"; $username = "your_username"; $password = "your_password"; $dbname = "your_database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("接続に失敗しました: " . $conn->connect_error); } $pref = $_POST['pref']; $comment = $_POST['comment']; $sql = "INSERT INTO your_table (pref, comment) VALUES ('$pref', '$comment')"; if ($conn->query($sql) === TRUE) { echo "新しいレコードが作成されました"; } else { echo "エラー: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
// データを挿入または更新するSQL文 $sql = "INSERT INTO your_table (id, column1, column2) VALUES (:id, :column1, :column2) ON DUPLICATE KEY UPDATE column1 = VALUES(column1), column2 = VALUES(column2)"; $stmt = $pdo->prepare($sql); // パラメータの設定 $stmt->bindParam(':id', $id); $stmt->bindParam(':column1', $column1); $stmt->bindParam(':column2', $column2);
主キー(またはユニークキー)に基づいて動作します。これは、重複するキーがある場合にUPDATEを実行するためです。したがって、この構文を使用する場合は、必ずしもIDである必要はありませんが、ユニークキーまたは主キーに基づく必要があります。
複数のカラムを組み合わせてユニークキーを作ることは可能ですし、それを使ってINSERT ... ON DUPLICATE KEY UPDATE構文を使用することも可能です。実際、複合ユニークキーを設定すれば、複数カラムの組み合わせに基づいてINSERTまたはUPDATEを行うことができます。
例えば、次のように複合ユニークキーを設定します:
CREATE TABLE your_table ( id INT AUTO_INCREMENT PRIMARY KEY, column1 VARCHAR(255), column2 VARCHAR(255), column3 VARCHAR(255), UNIQUE KEY unique_key (column1, column2) );
このようにテーブルを作成した場合、column1とcolumn2の組み合わせがユニークキーとして機能します。これに基づいてINSERT ... ON DUPLICATE KEY UPDATE構文を使用する例を以下に示します:
// データを挿入または更新するSQL文 $sql = "INSERT INTO your_table (column1, column2, column3) VALUES (:column1, :column2, :column3) ON DUPLICATE KEY UPDATE column3 = VALUES(column3)"; $stmt = $pdo->prepare($sql); // パラメータの設定 $stmt->bindParam(':column1', $column1); $stmt->bindParam(':column2', $column2); $stmt->bindParam(':column3', $column3);
この例では、column1とcolumn2の組み合わせがユニークであるため、重複するデータがある場合にはcolumn3が更新され、重複しない場合には新しいレコードが挿入されます。
この方法なら複数カラムのユニーク性を活かしてデータの挿入および更新ができます。
CREATE TABLE your_table ( id INT AUTO_INCREMENT PRIMARY KEY, column1 VARCHAR(255) NOT NULL, column2 VARCHAR(255) NOT NULL, column3 VARCHAR(255), UNIQUE KEY unique_key (column1, column2) );
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\SMTP; require 'path/to/PHPMailer/src/Exception.php'; require 'path/to/PHPMailer/src/PHPMailer.php'; require 'path/to/PHPMailer/src/SMTP.php'; function sendMail($to, $toname, $subject, $body) { // 文字エンコードを指定 mb_language('uni'); mb_internal_encoding('UTF-8'); $mail = new PHPMailer(true); try { //Enable SMTP debugging //SMTP::DEBUG_OFF = off (for production use) //SMTP::DEBUG_CLIENT = client messages //SMTP::DEBUG_SERVER = client and server messages $mail->SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->Host = SMTP_SERVER; $mail->SMTPAuth = true; $mail->Username = SMTP_USER; $mail->Password = SMTP_PASS; $mail->SMTPSecure = 'tls'; $mail->Port = SMTP_PORT; $mail->CharSet = "utf-8"; $mail->setFrom(FROM_MAIL, SITE_NAME); $mail->addAddress($to, $toname); //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); //Attachments //$mail->addAttachment('/var/tmp/file.tar.gz'); //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $body; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } ?>
Fatal error: Uncaught Error: Class "SMTP" not found
use PHPMailer\PHPMailer\SMTP;
SMTPプロトコルを使用してメールを送信することができ、メッセージの配信可能性が向上します。また、SMTPクラスを使用することで、エラーハンドリングやデバッグ機能も利用できるようになり、問題が発生した際の原因特定が容易になります。
Web上だと送料が一回注文時のものとなるので、電話で依頼する。
# dnf install dnf5-plugin-automatic Updating and loading repositories: Repositories loaded. Failed to resolve the transaction: Problem: conflicting requests - package dnf5-plugin-automatic-5.2.6.2-1.fc41.x86_64 from fedora requires libcurl-full(x86-64), but none of the providers can be installed - package dnf5-plugin-automatic-5.2.7.0-1.fc41.x86_64 from updates requires libcurl-full(x86-64), but none of the providers can be installed - problem with installed package - installed package libcurl-minimal-8.9.1-2.fc41.x86_64 conflicts with libcurl(x86-64) provided by libcurl-8.9.1-2.fc41.x86_64 from fedora - package libcurl-minimal-8.9.1-2.fc41.x86_64 from fedora conflicts with libcurl(x86-64) provided by libcurl-8.9.1-2.fc41.x86_64 from fedora You can try to add to command line: --allowerasing to allow erasing of installed packages to resolve problems --skip-broken to skip uninstallable packages
インストール中に依存関係の問題が発生した場合、特にlibcurlに関連する競合が報告されています。その場合は、次のコマンドで競合するパッケージを交換できます:
# dnf swap libcurl-minimal libcurl
インストール後、設定ファイルを作成します:
# cp /usr/share/dnf5/dnf5-plugins/automatic.conf /etc/dnf/dnf5-plugins/automatic.conf
設定ファイルを編集して自動アップデートを設定します。例えば:
# vi /etc/dnf/dnf5-plugins/automatic.conf
[commands] # Whether updates should be applied when they are available, by # dnf5 automatic. apply_updates = yes
dnf5-automatic.service の ExecStart に --installupdates を追加。
# vi /usr/lib/systemd/system/dnf5-automatic.service
ExecStart=/usr/bin/dnf5 automatic --timer --installupdates
最後に、自動アップデート機能を有効化します:
# systemctl enable --now dnf5-automatic.timer
マジ?
相互依存性:
apply_updatesがyesでも、タイマーが無効なら自動更新は実行されません。
タイマーが有効でも、apply_updatesがnoなら更新は適用されません。
自動インストールを行うためには、download_updates = yes の設定に加えて、dnf-automatic-install.timer を有効にする必要があります。これにより、ダウンロードされた更新パッケージが自動的にインストールされます。
日本では、マイナンバーカードや運転免許証のどちらか一方を持っていれば、身分証明書として認められます。ただし、どちらの証明書を持っているかによって、利用できるサービスや場面が異なる場合があります。
マイナンバーカードは無料で発行されます。申請手続きや発行自体には費用がかかりませんが、もしカードを紛失したり再発行が必要な場合には、再発行手数料がかかることがあります。
マイナンバーカードには有効期限があります。具体的には、20歳以上の方は10年間の有効期限があり、20歳未満の方は5年間の有効期限です。期限が切れる前に更新手続きを行う必要がありますが、カード自体の更新手数料は基本的には無料です。
Apacheのデフォルト設定により、.htaccessファイルへのアクセスはデフォルトで拒否されるように設定されている場合があります。具体的には、Apacheの設定ファイル(通常はhttpd.confやapache2.conf)に以下のようなディレクティブが含まれていることが多いです:
<Files ".ht*"> Require all denied </Files>
この設定により、ファイル名が「.ht」で始まるファイル(例:.htaccessや.htpasswd)へのアクセスが全て拒否されるようになっています。これにより、これらのファイルがウェブ経由で閲覧されることを防ぎ、セキュリティを強化しています。
function isEdge() { return /Edge/.test(navigator.userAgent); } if (isEdge()) { console.log("This is Edge browser."); } else { console.log("This is not Edge browser."); }
shuffledString = string.split('').sort(() => .5 - Math.random()).join('');