PHP初心者です。会員サイト作成しており、register_check.phpファイルにWarning: htmlspecialchars() expects parameter 1 to be string, array givenのエラーが出ており調べた所「isset関数」を使えば良いとのことですが、どこの使えば良いのかもわからず困っております。ご教授頂ければ幸いです。よろしくお願いします。
touroku.php
<table>
<label for="birth_y">生年月日</label>
<td class="birthday">
<select name="birth_y" id="birth_y">
<select name="birth_m">
<select name="birth_d">
<input type="text" id="zip21" name="zip21" size="4" maxlength="3" class="z1">
<span id="pref21_error"><label for="pref21" class="Error" generated="true"></label><span>数字は半角で入力して下さい。</span></span>
<b class="postal_code">郵便番号を入力すると住所が自動的に入力されます。</b>
<th><label for="pref21">都道府県</label></th>
<select id="pref21" name="pref21">
<th><label for="addr21">市区町村・番地</label></th>
<input type="text" name="addr21" id="addr21" class="required inp" size="60">
<th><label for="street">マンション・建物名</label></th>
<input type="text" name="street" id="street" title="例)くにおビル3号室">
</table>
************************************
register_check.php
<?php
require_once 'MDB2.php';
require_once("function.php");
session_start();
header("Content-type: text/html; charset=utf-8");
$_SESSION['token'] = get_csrf_token();
$name = $_POST['full_name'];
$name_kana = $_POST['furigana'];
$birthday = array($_POST['birth_y'],$_POST['birth_m'],$_POST['birth_d']);
$postcode = array($_POST['zip21'],$_POST['zip22']);
$address = array($_POST['pref21'],$_POST['addr21'].$POST['street']);
$mail = $_POST['mail1'];
$telephone = $_POST['tel'];
$password = $_POST["password1"];
$confirm_password = $_POST["password2"];
if ($password != $confirm_password) {
$_SESSION["error_status"] = 1;
header("HTTP/1.1 301 Moved Permanently");
header("Location: register.php");
exit();
}
$db = MDB2::connect(DNS);
if (PEAR::isError($db)) {
die($db->getMessage());
}
$sql = "SELECT COUNT(*) AS CNT FROM USERS WHERE ID = ? ;";
$stmt = $db->prepare($sql, array('text'));
$rs = $stmt->execute(array($id));
while ($row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC)) {
$count = $row['cnt'];
var_dump($row);
}
$db->disconnect();
if ($count != 0) {
$_SESSION["error_status"] = 2;
header("HTTP/1.1 301 Moved Permanently");
header("Location: touroku.php");
exit();
}
$_SESSION["error_status"] = 0;
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<html lang="ja">
<body>
<input type="hidden" name="name" value="<?php echo htmlspecialchars($name , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="name_kana" value="<?php echo htmlspecialchars($name_kana , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="birthday" value="<?php echo htmlspecialchars($birthday , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="postcode" value="<?php echo htmlspecialchars($postcode , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="address" value="<?php echo htmlspecialchars($address , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="mail" value="<?php echo htmlspecialchars($mail , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="telephone" value="<?php echo htmlspecialchars($telephone , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="password" value="<?php echo htmlspecialchars($password , ENT_QUOTES, "UTF-8") ?>">
<input type="hidden" name="token" value="<?php echo htmlspecialchars($_SESSION['token'] , ENT_QUOTES, "UTF-8") ?>">
<input type="submit" value="登録">
<input type="button" value="戻る" onclick="history.back();">
</form></body></html>
No.2ベストアンサー
- 回答日時:
No1の最終行は↓ですね、失礼しました。
$birthday = $_POST['birth_y'] . "/" . $_POST['birth_m'] . "/" . $_POST['birth_d'];
No.1
- 回答日時:
> Warning: htmlspecialchars() expects parameter 1 to be string, array given
表示されている警告メッセージを読みましょうよ。
"htmlspecialchars() はパラメータ1として文字列を期待しますが、arrayが与えられています。"
$birthday = array($_POST['birth_y'],$_POST['birth_m'],$_POST['birth_d']);
$postcode = array($_POST['zip21'],$_POST['zip22']);
$address = array($_POST['pref21'],$_POST['addr21'].$POST['street']);
↑でarrayが変数に代入されていますよね。
例えば下記の様にして文字列を代入すべきではないでしょうか?
$birthday = $_POST['birth_y'] + "/" + $_POST['birth_m'] + "/" + $_POST['birth_d'];
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
PHPのページ間による配列の受け...
-
PHP ボタンが押されたら処理を...
-
テキストボックスに初期値を入れる
-
パラメーターを隠す
-
複数チェックボックスの入力制...
-
入力フォーム→確認画面→送信画...
-
PHPで画像の渡しが上手く行きま...
-
画像ボタンをクリックした時の...
-
検索時の選択内容を保持する方法
-
PHPによるCSVファイルの指定列...
-
チェックボックスの必須項目指定
-
ゼロ除算
-
フォームでのリセットを使う方法
-
フォームのradioを使ってsubmit...
-
Javascript→PHPに...
-
<input type="hidden" >で配列...
-
特殊文字を含むフォームデータ...
-
フォーム送信後の更新ボタンで...
-
複数のセレクトボックスを1つに...
-
セレクトしたときに全て初期状...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
HTMLで前の画面に戻る時、入力...
-
PHP ボタンが押されたら処理を...
-
<input type="hidden" >で配列...
-
検索時の選択内容を保持する方法
-
フォームへの前回入力値をクリ...
-
フォームでのリセットを使う方法
-
PHPで画像の渡しが上手く行きま...
-
画面が更新されてもチェックボ...
-
フォームボタンを押すたびに数...
-
ラジオボタンをsessionで使いたい
-
テキストボックスに初期値を入れる
-
syntax error, unexpected '}' ...
-
【HTML(PHP?)】複数のフォーム...
-
チェックボックスの必須項目指定
-
HTMLのリンクをクリックするこ...
-
DBの値をチェックボックスに反...
-
複数チェックボックスの入力制...
-
チェックボックスのvalueに変数...
-
input nameで日本語を使うと
-
POSTデータのNAME属性をVALUEに...
おすすめ情報