2017-11-14 12 views
0
<form action="action.php" method="POST" target="_self"> 
<table class="main" border="1" height="100%" align="center"> 
<h3> 
<p id="id1" style="background-color: #9FF" >Registration form</p></h3> 

<tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text" name="fname" value="" placeholder="firstname" required="required" maxlength="25"></td></tr> 
<tr><td> SurName:<span style="color:red">*</span></td> 
<td><input type="text" name="sname" value="" placeholder="lastname" required="required" maxlength="20"/> </td></tr> 
<tr><td>Age:<span style="color:red">*</span></td> 
<td> <input type="text" name="age" value="" required/></td></tr> 
<tr><td>Date of Birth:<span style="color:red">*</span></td> 
<td><input type="date" name="DOB" value="" required/></td></tr> 
<tr><td> Gender:<span style="color:red">*</span></td> 
    <td><input type="radio" name="gender" value="male" required/>Male 
    <input type="radio" name="gender" value="Female" />Female</td></tr> 
    <tr><td>Qualification:<span style="color:red">*</span></td> 
    <td> <select name="study" required> 
    <option value="">---Select---</option> 
    <option value="btech">B.Tech</option> 
    <option value="BSc">BSc</option> 
    <option value="BCom">BCom</option> 
</select></td></tr> 
    <tr><td> State:<span style="color:red">*</span></td> 
<td><Select name="state" required > 
<option value="">---Select---</option> 
<option valuie="AndhraPradesh">AndhraPradesh</option> 
<option value="Telangana">Telangana</option> 
<option value="Tamilnadu">Tamilnadu</option> 
<option value="Kerala">Kerala</option> 
<option vgalue="Maharastra">Maharastra</option> 
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td><input type="checkbox" name="profile" value="Java" />Java 
          <input type="checkbox" name="profile" value="PHP" />PHP 
          <input type="checkbox" name="profile" val 

    ue="Android" />Android</td> </tr> 
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr> 
      <tr><td colspan="2" align="center"><input type="submit" value="submit" /></td></tr>     
    </table></form> 

**これは私のレジスタの形態であり、今私は、次のページaction.phpで、すなわち、そのコード内の選択されたすべての値を表示したいリダイレクトされたページのドロップダウンとチェックボックスの選択値を確認のために表示するにはPHP?

<form action="store.php" method="post" align="center" target="_self"> 
    <label>Name of the person:</label> 
    <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?> <br /> 
    <label>Name of the Surname:</label> 
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?> <br /> 
    <label>His Age:</label> 
    <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br /> 
    <label>Date of Birth:</label> 
    <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?> <br /> 
     <label>Gender:</label> 
    <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br /> 
     <label>Education:</label> 
    <input type="hidden" name="edu" value="<?php if(isset($_POST['submit']))echo $_POST['study']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study']?>;?> 
     <br /> 
     <label>State:</label> 
     <input type="hidden" name="state" value="<?if(isset($_POST['submit']))echo $_POST['state']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state']?>;?> 
     <br /> 
     <label>Good At:</label> 
    <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?> <br /> 
     <label>Address:</label> 
     <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?> <br /><br /><br /> 
     <input type="submit" value="confirm" name="submit"></input> 
********次のようです

****ドロップダウンが表示されていないことを確認し、確認の後に確認された値がデータベースに保存されている必要があることをお勧めします。これはaction.phpの入力隠しフィールドの名前登録入力フィールド名?

答えて

1
ポストを提出したとき $_POST['abc']の値が option1あり得ます
  1. コードに構文エラーが多数あります。
  2. 送信ボタンにという名前の属性を追加していません。 name = "submit"が含まれている必要があります。それ以外の場合は、ドロップダウン値を表示するときにコード内でチェックインされています($ _POST配列にsubmitという名前の変数が見つからないため)。
  3. このチェックボックスは同じ名前を使用しています。だからそれは配列でなければなりません。 [] 名=プロファイルを使用代わり名=プロファイルの

に最後にform.phpは次のようになります。

<form action="action.php" method="POST" target="_self"> 
<table class="main" border="1" height="100%" align="center"> 
<h3> 
<p id="id1" style="background-color: #9FF" >Registration form</p></h3> 

<tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text" name="fname" value="" placeholder="firstname" required="required" maxlength="25"></td></tr> 
<tr><td> SurName:<span style="color:red">*</span></td> 
<td><input type="text" name="sname" value="" placeholder="lastname" required="required" maxlength="20"/> </td></tr> 
<tr><td>Age:<span style="color:red">*</span></td> 
<td> <input type="text" name="age" value="" required/></td></tr> 
<tr><td>Date of Birth:<span style="color:red">*</span></td> 
<td><input type="date" name="DOB" value="" required/></td></tr> 
<tr><td> Gender:<span style="color:red">*</span></td> 
    <td><input type="radio" name="gender" value="male" required/>Male 
    <input type="radio" name="gender" value="Female" />Female</td></tr> 
    <tr><td>Qualification:<span style="color:red">*</span></td> 
    <td> <select name="study" required> 
    <option value="">---Select---</option> 
    <option value="btech">B.Tech</option> 
    <option value="BSc">BSc</option> 
    <option value="BCom">BCom</option> 
</select></td></tr> 
    <tr><td> State:<span style="color:red">*</span></td> 
<td><Select name="state" required > 
<option value="">---Select---</option> 
<option value="AndhraPradesh">AndhraPradesh</option> 
<option value="Telangana">Telangana</option> 
<option value="Tamilnadu">Tamilnadu</option> 
<option value="Kerala">Kerala</option> 
<option vgalue="Maharastra">Maharastra</option> 
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td> 

       <input type="checkbox" name="profile[]" value="Java" />Java 
          <input type="checkbox" name="profile[]" value="PHP" />PHP 
          <input type="checkbox" name="profile[]" value="Android" />Android</td> </tr> 
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr> 
      <tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit" /></td></tr>     
    </table></form> 

そしてaction.phpがあるべきこのように:

<form action="store.php" method="post" align="center" target="_self"> 
    <label>Name of the person:</label> 
    <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?> <br /> 
    <label>Name of the Surname:</label> 
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?> <br /> 
    <label>His Age:</label> 
    <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br /> 
    <label>Date of Birth:</label> 
    <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?> <br /> 
     <label>Gender:</label> 
    <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br /> 
     <label>Education:</label> 
    <input type="hidden" name="edu" value="<?php if(isset($_POST['submit'])) echo $_POST['study'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study'];?> 
     <br /> 
     <label>State:</label> 
     <input type="hidden" name="state" value="<?if(isset($_POST['submit'])) echo $_POST['state'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state'];?> 
     <br /> 
     <label>Good At:</label> 
    <input type="hidden" name="profile" value="<?php echo implode(", ", $_POST['profile']); ?>"> 
<?php 
echo implode(", ", $_POST['profile']); 
//print_r($_POST['profile']); 
?> 

<br /> 
     <label>Address:</label> 
     <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?> <br /><br /><br /> 
     <input type="submit" value="confirm" name="submit"></input> 

データベースに格納するデータは、データベース設計によって異なります。

例:チェックボックス の値をコンマ区切り文字列として保存するか、別のテーブルを使用するかによって異なります。

あなたのプログラムのこの時点で、action.phpページに入ったら、登録フォームを使って取得したデータをセッションを使ってstore.phpに送ることができます。それ以外の場合はstore.phpで$ _POSTを使用すると、action.phpページの非表示の入力フィールドに入力値が表示されます。

+0

これがあなたが探していたものかどうか教えてください。 – Anjana

0

私は、コードを少し変更している...あなたはいくつかのマイナーな構文の間違いを持っ​​ていた...

<form action="store.php" method="post" align="center" target="_self"> 
    <label>Name of the person:</label> 
    <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?> <br /> 
    <label>Name of the Surname:</label> 
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?> <br /> 
    <label>His Age:</label> 
    <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br /> 
    <label>Date of Birth:</label> 
    <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?> <br /> 
     <label>Gender:</label> 
    <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br /> 
     <label>Education:</label> 
    <input type="hidden" name="edu" value="<?php echo $_POST['study']; ?>"></input><?php echo $_POST['study'];?> 
     <br /> 
     <label>State:</label> 
     <input type="hidden" name="state" value="<?php echo $_POST['state'];?>"></input><?php echo $_POST['state'];?> 
     <br /> 
     <label>Good At:</label> 
    <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?> <br /> 
     <label>Address:</label> 
     <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?> <br /><br /><br /> 
     <input type="submit" value="confirm" name="submit"></input> 
+0

回答はqですが、ドロップダウンリストとチェックボックスについては質問しません。テキストフィールドの値は正確に –

0
<SELECT name="abc"> 
<option value="option1" selected> This is option 1 </option> 
<option value="option2"> This is option 2 </option> 
</SELECT> 

とPHP

+0

です。 echo $ _POST ['study'];?>選択された値が表示されていません。 –

+0

あなたの 'php.ini'の短い公開タグを有効にします。 https://stackoverflow.com/questions/4645898/how-to-set-short-tag-in-php。あなたがそれを持っていれば、このコメントに投票してください –

関連する問題