2017-01-16 6 views
1

このページにはフォームがあり、前のページの$ _GET値があります。フォームが提出された後に「未定義インデックス」エラーが発生しました

$event_id = $_GET["event_id"]; 
$event_host_id = $_GET["event_user_id"]; 
$host_username = $_GET["username"]; 
$event_name = $_GET["event_name"]; 
$sport = $_GET["sport"]; 
$description = $_GET["description"]; 
$location = $_GET["location"]; 
$event_date = $_GET["event_date"]; 
$formatted_event_date = date("D jS F Y g:i a", strtotime($event_date)); 
$number_of_tickets = $_GET["number_of_tickets"]; 
$tick_end_date = $_GET["tick_end_date"]; 
$formatted_t_e_d = date("D jS F Y g:i a", strtotime($tick_end_date)); 
$tickets_remaining = $_GET["tickets_remaining"]; 

ページが正常に読み込まれ、GET変数が問題なく使用されます。使用

<form action="give_feedback.php" method="POST"> 
    Rating<input name="rating" type="range" min="0" max="10" value="0" step="1" onchange="showValue(this.value)" /> 
    <span id="range">0 /10</span> 
    <script type="text/javascript"> 
     function showValue(newValue) { 
      document.getElementById("range").innerHTML=newValue + " /10"; 
     } 
    </script><br><br> 
    <textarea name="comment" rows="4" cols="30" selectionStart spellcheck="true" placeholder="Feedback comment"></textarea><br> 
    <input type="submit" value="submit_feedback" name="submit_feedback" /> 
</form> 

::私は私のフォームを送信するとき しかし、

if(isset($_POST["submit_feedback"])) { 
    if(true) { 
     //DO FORM VERIFICATION HERE 
     $rating = (int)($_POST["rating"]); 
     $comment = mysqli_real_escape_string($connection, $_POST["comment"]); 

     $query = "UPDATE `booking_dates` SET `rating` = '$rating', `comment` = '$comment' WHERE `user_id` = '$user_id' AND `event_id` = '$event_id'"; 
     $result = mysqli_query($connection, $query); 
     check_query_result($result); 
    } 
} 

を前に、完全に罰金だったGET変数のすべてのための未定義のインデックスエラーがありますので、私のクエリが送信できません。 はここgive_feedback.phpファイルの完全なコードです:

<?php 
require('includes/session.php'); 
require('includes/connect.php'); 
require('includes/functions.php'); 
?> 

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <link href="stylesheets/layout.css" media="all" rel="stylesheet" type="text/css" /> 

     <title>My account</title> 
    </head> 
    <body> 
     <div id="Holder"> 
      <div> 
       <img class="logo" src="images/sports%20world%20logo.png" width="400px" height="200px"> 
      </div> 
      <div> 
       <p class="logged_in">Logged in as <?php echo htmlentities($_SESSION["username"]); ?></p> 
      </div> 
      <div id="NavBar"> 
       <nav> 
        <ul> 
         <li><a href="LoggedInIndex.php">All Events</a></li> 
         <li><a href="create_event.php">Create Event</a></li> 
         <li class="selected"><a href="my_account.php">My account</a></li> 
         <li><a href="event_ratings.php">Event Ratings</a></li> 
         <li><a href="log_out.php">Log Out</a></li> 
        </ul> 
       </nav> 
      </div> 
      <div id="Content"> 
       <div id="PageHeading"> 
        <h1 id="Header">Give feedback on this event:</h1> 
       </div> 
       <?php 
       $user_id = $_SESSION["user_id"]; 
       if(isset($_GET["event_id"])){ 
        $event_id = $_GET["event_id"]; 
       } 
       if(isset($_GET["event_user_id"])){ 
        $event_host_id = $_GET["event_user_id"]; 
       } 
       if(isset($_GET["username"])){ 
        $host_username = $_GET["username"]; 
       } 
       if(isset($_GET["event_name"])){ 
        $event_name = $_GET["event_name"]; 
       } 
       if(isset($_GET["sport"])){ 
        $sport = $_GET["sport"]; 
       } 
       if(isset($_GET["description"])){ 
        $description = $_GET["description"]; 
       } 
       if(isset($_GET["location"])){ 
        $location = $_GET["location"]; 
       } 
       if(isset($_GET["event_date"])){ 
        $event_date = $_GET["event_date"]; 
       } 
       $formatted_event_date = date("D jS F Y g:i a", strtotime($event_date)); 
       ?> 

       <div class="boxed"> 
        <div class="left"> 
         <h3><u><?php echo $event_id; ?></u></h3> 
         <h3><u><?php echo $event_name; ?></u></h3> 
         <h4>Hosted By <?php echo $host_username; ?></h4> 
         <p><?php echo $description; ?></p> 

         <h5><a href="my_account.php">Back To My Events</a></h5> 

        </div> 
        <div class="right"> 
         <table> 
          <tr> 
           <td class="table_left">Sport</td> 
           <td class="table_right"><?php echo $sport; ?></td> 
          </tr> 
          <tr> 
           <td class="table_left">Location</td> 
           <td class="table_right"><?php echo $location; ?></td> 
          </tr> 
          <tr> 
           <td class="table_left">Date</td> 
           <td class="table_right"><?php echo $formatted_event_date; ?></td> 
          </tr> 

         </table> 
        </div> 
       </div> 
       <div class="bottom"> 
        <h2>Your feedback:</h2> 
        <form action="give_feedback.php" method="POST"> 
         Rating<input name="rating" type="range" min="0" max="10" value="0" step="1" onchange="showValue(this.value)" /> 
         <span id="range">0 /10</span> 
         <script type="text/javascript"> 
          function showValue(newValue) 
          { 
           document.getElementById("range").innerHTML=newValue + " /10"; 
          } 
         </script><br><br> 
         <textarea name="comment" rows="4" cols="30" selectionStart spellcheck="true" placeholder="Feedback comment"></textarea><br> 
         <input type="submit" value="submit_feedback" name="submit_feedback" /> 
        </form> 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 

<?php  
if(isset($_POST["submit_feedback"])){ 
    if(true){//DO FORM VERIFICATION HERE 
     $rating = (int)($_POST["rating"]); 
     $comment = mysqli_real_escape_string($connection, $_POST["comment"]); 

     echo $rating; 
     echo "<br>"; 
     echo $comment; 

     $query = "UPDATE `booking_dates` SET `rating` = '$rating', `comment` = '$comment' WHERE `user_id` = '$user_id' AND `event_id` = '$event_id'"; 
     $result = mysqli_query($connection, $query); 
     check_query_result($result); 
    } 

} 

?> 
+0

ここでphpが取得するフォームの入力フィールドは?私はまたあなたがフォームをポストしているが、PHPで取得していることに注意してください。全体を通してポストを使用したり、コードを変更して使用する必要があります。 – Chris

+0

@ChrisフォームをGETに変更しましたが、同じ問題が引き続き発生します。私のフォーム入力フィールドは、テキストボックスとスライダです – asker

+0

それはあなたがなぜあなたのコードに表示されない理由を説明して、あなたもifブロックの投稿を変更しましたか? – Chris

答えて

0

以前のフォームからの$ GETの値は渡しませんフォームを送信します。すべての$ GET変数にif(isset())条件を追加することで、エラーを回避できます。

 if(isset($_GET["event_id"])){ $event_id = $_GET["event_id"]; } 
     if(isset($_GET["event_user_id"])){ $event_host_id = $_GET["event_user_id"]; } 
     . 
     .. 


     .. 

     . 

     . 

     . 
     if(isset($_GET["tickets_remaining"])){ $tickets_remaining = $_GET["tickets_remaining"]; } 

OR

パスすべてが送信されたフォームに値を取得します。

+0

私はすべての変数を取得するためにissetを追加しましたが、今は"未定義の変数 "というエラーが発生します... – asker

+0

提出されたフォームにすべての値を渡すとはどういう意味ですか? – asker

+0

フォーム提出後にこれらの変数($ event_id、$ event_host_idなど)が必要な場合は、これらの値をすべて次のフォームに渡す必要があります。 – mith

0

各データタイプのデータタイプと長さを含むデータベーステーブルを確認してください。

関連する問題