前提・実現したいこと
電話番号(tel)が登録入力と違う番号で登録されてしまいます。
原因を探しましたがわかりませんでした。
わかる方教えて頂きたいです。
宜しくお願い致します。
該当のソースコード
user_register.php <?php error_reporting(E_ALL); ini_set("display_errors",1); session_start(); if( isset($_SESSION['user']) != "") { header("Location: user_home.php"); } try { $db['host'] = "localhost"; $db['user'] = "root"; $db['pass'] = ""; $db['dbname'] = "reserve"; // メッセージの初期化 $errorMessage = ""; $signUpMessage =""; // ログインボタンが押された場合 if (isset($_POST["signUp"])) { // 1. ユーザIDの入力チェック if (empty($_POST["user_name"])) { // 値が空のとき $errorMessage = '名前が未入力です。'; } else if (empty($_POST["tel"])) { // 値が空のとき $errorMessage = '電話番号が未入力です。'; } else if (empty($_POST["user_password"])) { $errorMessage = 'パスワードが未入力です。'; } else if (empty($_POST["user_password2"])) { $errorMessage = 'パスワードが未入力です。'; } if (!empty($_POST["user_name"]) && !empty($_POST["tel"]) && !empty($_POST["user_password"]) && !empty($_POST["user_password2"]) && $_POST["user_password"] === $_POST["user_password2"]) { // 入力したユーザIDとパスワードを格納 $user_name = $_POST["user_name"]; $tel = $_POST["tel"]; $user_password = $_POST["user_password"]; // 2. ユーザIDとパスワードが入力されていたら認証する $dsn = sprintf('mysql: host=%s; dbname=%s;charset=utf8', $db['host'], $db['dbname']); $pdo = new PDO($dsn, $db['user'], $db['pass'], array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare("INSERT INTO users(user_name,tel,user_password) VALUES (?, ?, ?)"); $stmt->execute(array($user_name,$tel, password_hash($user_password, PASSWORD_DEFAULT))); $user_id = $pdo->lastinsertid(); // 登録した(DB側でauto_incrementした)IDを$useridに入れる $signUpMessage = '登録が完了しました。'; } else if($_POST["user_password"] != $_POST["user_password2"]) { $errorMessage = 'パスワードに誤りがあります。'; } } } catch (PDOException $e) { var_dump($e); die(); } ?> <!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="utf-8" > <meta name="viewport" content="width=device-width, initial-scale=1"> <title>ユーザー登録ページ</title> <link href="style.css" rel="stylesheet" type="text/css" media="all"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> </head> <body> <div class="header" > <div class="col-xs-12" style="line-height:100px;color:white;background-color:rgb(27, 26, 26);text-align:center;height:100px;"> <a href="#" style="color:white;">サイト名</a> </div> </div> <div class="main"> <div class="container" > <div class="row"> <div class="col-sm-10 offset-sm-1" style="padding-bottom:30%;background-color:rgb(237, 237, 237);width:100%;text-align:center;"> <form id="loginForm" name="loginForm" action="" method="POST" style=""> <p class="alert alert-success" style="text-align:center;">新規登録</p> <div class="form" style=""> <div><font color="#ff0000"><?php echo htmlspecialchars($errorMessage, ENT_QUOTES); ?></font></div> <div><font color="#0000ff"><?php echo htmlspecialchars($signUpMessage, ENT_QUOTES); ?></font></div> <div class="form-group" style="text-align:left;"> <label for="user_name">名前</label><br> <input style="width:100%;" name="user_name" type="text" id="user_name" placeholder="名前" value="<?php if (!empty($_POST["user_name"])) {$_POST["user_name"];} ?>"><br><br> </div> <div class="form-group" style="text-align:left;"> <label for="tel">電話番号</label><br> <input style="width:100%;" name="tel" type="tel" id="tel" placeholder="電話番号11桁" value="<?php if (!empty($_POST["tel"])) {echo $_POST["tel"];} ?>"><br><br> </div> <div class="form-group" style="text-align:left;"> <label for="user_password">パスワード</label><br> <input style="width:100%;" name="user_password" type="password" id="user_password" value="" placeholder="パスワードを入力"><br><br> </div> <div class="form-group" style="text-align:left;"> <label for="user_password2">パスワード(確認用)</label><br> <input style="width:100%;" name="user_password2" type="password2" id="user_password2" value="" placeholder="再度パスワードを入力"><br><br> </div> <button type="submit" class="btn btn-success" name="signUp" id="signUp" style="width:100%;">新規登録</button> </div> <a href="user_index.php" style="">ログインする</a> </form> </div> </div> </div> <?php include("footer.html");?> </body> </html>
var_dump
object(PDOException)#3 (8) { ["message":protected]=> string(96) "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2147483647' for key 'tel'" ["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "23000" ["file":protected]=> string(46) "C:\xampp\htdocs\reserve\user\user_register.php" ["line":protected]=> int(45) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(46) "C:\xampp\htdocs\reserve\user\user_register.php" ["line"]=> int(45) ["function"]=> string(7) "execute" ["class"]=> string(12) "PDOStatement" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(3) { [0]=> string(9) "ゆうた" [1]=> string(11) "08081351695" [2]=> string(60) "$2y$10$uSXXKNpMzcmxCbwwRf.Ld.dRt0xMLF1TbaguERkahvFlmIlUUWaGu" } } } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "23000" [1]=> int(1062) [2]=> string(42) "Duplicate entry '2147483647' for key 'tel'" } }
補足情報(FW/ツールのバージョンなど)
Apache/2.4.39 (Win64) OpenSSL/1.1.1b PHP/7.3.5
ここにより詳細な情報を記載してください。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/29 04:19 編集
2019/05/29 04:22
2019/05/29 04:25
2019/05/29 07:00 編集
2019/05/29 04:29
2019/05/29 04:34
2019/05/29 04:35