dポイントプレゼントキャンペーン実施中!

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>

A 回答 (2件)

No1の最終行は↓ですね、失礼しました。


$birthday = $_POST['birth_y'] . "/" . $_POST['birth_m'] . "/" . $_POST['birth_d'];
    • good
    • 0

> 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'];
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!