0

私は現在、休日を保存するために使用される配列にxmlタイトルの値を投稿しようとしています。まだエラー メッセージが表示されず、var_dump を使用して次の情報を収集しました。(RSS フィードの読み取りに関連するいくつかのチェック ボックスにチェックを入れます)

array(7) { [0]=> string(21) "{$currentItem->title}" [1]=> string(21)"{$currentItem->title}" [2]=> string(21) "{$currentItem->title}" [3]=> string(21) "{$currentItem->title}" [4]=> string(21) "{$currentItem->title}" [5]=> string(21) "{$currentItem->title}" [6]=> string(21) "{$currentItem->title}" } :S 

これは、配列側が機能していることを示していますが、すべての文字列が 21? であるため、チェック ボックスの値パラメーター内に設定された情報を保持していません。21 は、saveBox の値の引用符の間の文字数です!!

index.php のセクション

$index = 1;
    foreach ($allHolidays as $currentItem)
        {
            echo '<tr>';
            if (isset($_SESSION['login']))
                {
                    echo '<td valign="top">';
                    //echo '<input type="hidden" name="guid$index" value="{$currentItem->guid}">';name="saveBox$index[]"
                    echo '<input type="checkbox" name="saveBox[]" value="{$currentItem->title}">';
                    echo '</td>';
                }
            echo '<td>';
            echo "<p><a href=\"{$currentItem->link}\">{$currentItem->title}</a><br/>";
            echo "{$currentItem->description}<br/>";
            echo "{$currentItem->pubDate}<br/></p>";
            echo '</td>';
            echo '</tr>';
            $index++;
        }

saveProcess.php

<?php   
    header("refresh:555; url='index.php'");
    session_start();

    echo "Thank you for saving a holiday";
    echo '<input type="checkbox" name="saveBox[]" value="'.
    htmlspecialchars($currentItem->title).'">';
    include "top.php";
    var_dump($_POST['saveBox']);

    try
    {

        foreach ($_POST['saveBox'] as $savedHoliday)
        {
            $user = $_SESSION['login'];
            $currentSave = $savedHoliday;
            $save = "channel/item[title=\"$currentSave\"]";
            $holidaysXML = simplexml_load_file('holidays.xml');
            $savePath = $holidaysXML->xpath($save);
            foreach($savePath as $currentSavePath)
                    {
                        echo "<p><a href='{$currentSavePath->link}'>{$currentSavePath->title}</a>"."<br\>".
                        "{$currentSavePath->description}"."<br\>".
                        "{$currentSavePath->pubDate}"."<br\></p>";

                        $insertSave = $db->prepare("INSERT INTO `saved_holidays` (`subscriberID`, `link`, `pubDate`, `title`, `description`)
                        VALUES ('$user', '$currentSavePath->link', '$currentSavePath->pubDate', '$currentSavePath->title', '$currentSavePath->description')");

                        $insertSave->execute();
                    }

        }
    }
    catch(PDOException $e)
        {
            echo $e->getMessage();
        }
4

1 に答える 1

1

コンストラクトをsaveBox$index[]間違って使用しています。入力に名前を付けるだけでsaveBox[]、インデックスは忘れてください。$_POST['saveBox']受信側で読み取ると、PHP は自動的に配列を提供します。

htmlspecialcharsHTML に埋め込むすべてのデータも呼び出す必要があることを忘れないでください。

echo '<input type="checkbox" name="saveBox[]" value="'.
     htmlspecialchars($currentItem->title).'">';

と:

foreach ($_POST['saveBox'] as $savedHoliday)

余談ですが、出力を生成する前に常にheaderandを呼び出す必要があるため、出力を生成する場合は数行下に移動する必要があります。session_starttop.php

于 2012-05-02T10:54:25.673 に答える