1

ユーザーの選択に応じて、セッション変数に値を追加したいと思います。ユーザーは、イメージ マップ内のいくつかのエリア シェイプ内をクリックして、選択を行います。

これは私が持っているコードです。

<a class="selection_5M_platform"><img src="../../images/Selection/Windmillselection-platform5M-fullview.gif" usemap="#Windmillselection_Map5M_platform" alt="windmill_platform6M" name="windmill_platform6M">
    <map class="map" name="Windmillselection_Map5M_platform">          
      <area shape="poly" coords="12,131,56,131,61,133,68,136,74,140,74,345,12,345" href="../submitreport.php" onClick="<?php $_POST['selectedreportlocation']="5M_PLATFORM_LADDERS" ?>" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-ladders.gif',1)" alt="ladders_platform5M">                   
      <area shape="poly" coords="73,344,73,141,69,136,59,132,48,131,48,124,267,123,267,132,229,135,202,142,194,151,195,344" href="../submitreport.php" onClick="<?php $_SESSION['selectedreportlocation']="5M_PLATFORM_FOUNDATION" ?>" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-foundation.gif',1)" alt="foundation_platform5M">
      <area shape="poly" coords="148,121,177,121,177,46,125,6,47,6,47,74,58,74,58,46,105,52,109,67,121,67,126,54,148,58" href="../submitreport.php" onClick="<?php $_SESSION['selectedreportlocation']="5M_PLATFORM_PALFINGER" ?>" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-palfinger.gif',1)" alt="palfinger_platform5M">
      <area shape="poly" coords="49,123,49,92,149,92,149,121,177,121,177,91,187,62,271,60,268,90,268,123" href="../submitreport.php"  onMouseOut="MM_swapImgRestore()" onClick="<?php $_SESSION['selectedreportlocation']="5M_PLATFORM_GUARDRAIL" ?>" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-guardrail.gif',1)" alt="guardrail_platform5M">          
    </map>        
</a>

このコードの問題: どちらを選択しても問題ありません。セッション変数 (最後の「5M_PLATFORM_GUARDRAIL」) には常に同じ値が格納されます。

私は何を間違っていますか?

4

2 に答える 2

0

私の答えを役立つようにするために、私はこの解決策を提案します:

のHTMLマークアップを次のように置き換えます<map>

<map class="map" name="Windmillselection_Map5M_platform">          
    <area shape="poly" coords="12,131,56,131,61,133,68,136,74,140,74,345,12,345" href="../submitreport.php?location=5M_PLATFORM_LADDERS" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-ladders.gif',1)" alt="ladders_platform5M">
    <area shape="poly" coords="73,344,73,141,69,136,59,132,48,131,48,124,267,123,267,132,229,135,202,142,194,151,195,344" href="../submitreport.php?location=5M_PLATFORM_FOUNDATION" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-foundation.gif',1)" alt="foundation_platform5M">
    <area shape="poly" coords="148,121,177,121,177,46,125,6,47,6,47,74,58,74,58,46,105,52,109,67,121,67,126,54,148,58" href="../submitreport.php?location=5M_PLATFORM_PALFINGER" ?>" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-palfinger.gif',1)" alt="palfinger_platform5M">
  <area shape="poly" coords="49,123,49,92,149,92,149,121,177,121,177,91,187,62,271,60,268,90,268,123" href="../submitreport.php?location=5M_PLATFORM_GUARDRAIL"  onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('windmill_platform6M','','../../images/Selection/Windmillselection-platform5M-guardrail.gif',1)" alt="guardrail_platform5M">          
</map>

あなたの中に../submitreport.phpこのブロックを挿入する必要があります:

session_start();
$_SESSION['selectedreportlocation'] = $_GET['location'];

// session variable will be available from now 

PSあなたはサーバーサイドプログラミングの原則を完全に誤解しています。最初に、PHPに関するいくつかのチュートリアルを読む必要があります。

于 2012-10-18T17:19:07.440 に答える
0

PHP コード (サーバー コード) と JavaScript (クライアント コード) を混在させています。サーバー コードは、ページがレンダリングされる前に実行されます。したがって、php の最後の行が実行されます。HTML ソースを確認してください。そこに php コードが表示されません。

于 2012-10-18T17:01:11.470 に答える