0

次の結果を別のページに表示するにはどうすればよいですか。ユーザーが選択したものをエコーする必要があります。

<strong>Return</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($return as $return) { ?>
        <option value="<?php echo $return; ?>"><?php echo $return; ?></option>
    <?php } ?>

ありがとう

ユーザーが選択を行う場所の完全なコード。彼らがこのページで選択した情報は、私が別のページにエコーしたいものです.

<!DOCTYPE html>
<?php
session_start();
?>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="my.js">
        </script>
        <!-- User-generated css -->
        <style>
        </style>
        <!-- User-generated js -->
        <script>
            try {

    $(function() {

    });

  } catch (error) {
    console.error("Your javascript has an error: " + error);
  }
        </script>
     </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                    Back
                </a>
                <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d"class="ui-btn-right">
                 Home  
                </a>
                <h3>
                    Book Car
                </h3>
           </div>

           <div data-role="content">
                <h3>
                    Select date/time:
                </h3>
                <br />
<?php
{
    mysql_connect("localhost" , "" , "") or die (mysql_error());
    mysql_select_db("") or die(mysql_error());

    $query = "SELECT `book_time`, `book_date`, `return_time`, `return_date` FROM `Rental`";

    //executes query on the database
    $result = mysql_query ($query) or die ("didn't query");

    //this selects the results as rows
    $num = mysql_num_rows ($result);    

    $return = array();
    $rent = array();
    while($row=mysql_fetch_assoc($result))
    {

        $rent[] = $row['book_date'].' '.$row['book_time'];
        $return[] = $row['return_date'].' '.$row['return_time'];
    }
}
?>      

    <form method="post" action="car.php">
    <strong>Rent out</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($rent as $rent) { ?>
        <option value="<?php echo $rent; ?>"><?php echo $rent; ?></option>
    <?php } ?>

    </select>
    <br />

    <strong>Return</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($return as $return) { ?>
        <option value="<?php echo $return; ?>"><?php echo $return; ?></option>
    <?php } ?>


    </select>

                <br />
                <br />

                <input type="submit" name="Submit" value="Book" />
            </form>

             </div>
        </div>
    </body>
</html>
4

2 に答える 2

3

フォームの基本 101:

~~~index.php~~~
<form action='the_new_page.php' method='POST'>
  <input type='text' name='first_thing'>
  <input type='hidden' name='some_hidden_guy' value='1'>
  <input type='submit' name='submit_button' value='submit'>
</form>

ユーザーが上記のフォームを送信すると、ブラウザはユーザーを に誘導しthe_new_page.phpthe_new_page.phpすべてのフォーム情報を認識します。

フォームは と を渡しnameますvalue。知っておくべきことは他にはありません。idは純粋に html の目的のためのものであり、HTML の規則として、同じ ID を持つ複数の要素を持つことは許可されていません。人々は通常、フォーム フィールドの id をフォーム フィールドの「名前」と同じ名前にすると混乱を招きます。

したがって、フォームを送信すると、2 番目のページに移動し、次の操作を実行できます。

~~~the_new_page.php~~~
//You can then do
echo $_POST['some_hidden_guy'] //will be 1
echo $_POST['first_thing'] //Will be whatever you inserted into the text box

フォームを現在のページに戻したい場合は、またはのいずれかとして空白actionのままにします<form action=''><form method='POST'>

複数のページに同じ情報を保持する!

これは、どのページでも同じコードを繰り返す必要がないようにする方法を見つける必要があるため、これを行うには非常にプログラマーではない方法です。そうしないと、今警告しています..新しいフィールドを追加するたびにすべてのページを編集する必要があるため、このアプリのメンテナンスは悪夢になります. 例に進みます。

ここで、情報を car.php に渡し、それを carplan.php で使用したいとします。

~~~car.php~~~
    <form action='carplan.php' method='GET or POST, whichever it is you be using using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <option name='plan_id'>
            <?php foreach($plans as $plan): ?>
                <select value='<?php echo $plan['id'] ?>'><?php echo $plan['name'] ?>'>
            <?php endforeach; ?>
        </option>
        <input type='submit' name='submit' value='Get That Plan'>
    </form>

最後に carplan.php で

    ~~~carplan.php~~~
    <form action='the_next_step.php' method='GET or POST, whichever you be using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <input type='hidden' name='plan_id' value='<?php echo $_GET['plan_id']?>'>
        <input type='submit' name='submit' value='The next step!'>
    </form>
于 2013-04-09T21:02:01.077 に答える