2016-03-26 4 views
-2

テキストボックスのデータを次のページ(demo2)に渡したいので、すべてのデータを一緒にデータベースに保存する必要があります。私は渡された値は、次のページに送信しているが、私は、テキストボックスのデータを渡すことにしたい...以下phpの次のページへのセッションを使用してテキストボックスデータを渡す方法

は私のコード

demo1.php

<?php 
session_start(); 
if($_POST) 
{ 
     if($_POST['act'] == "add") 
    { 
     $firstname = $_POST['firstname']; 
     $lastname = $_POST['lastname']; 
     $nationality = $_POST['nationality']; 

     $conn = mysql_connect("localhost","root",""); 
     $db = mysql_select_db("reg",$conn); 

    } 
} 

echo "Session variables are set."; 

if(@$_GET) 
{ 
     $_SESSION["firstname"] = "$firstname"; 
     $_SESSION["lastname"] = " $lastname"; 
     $_SESSION["nationality"] = "$nationality"; 
     echo $firstname; 
     echo $lastname; 
     echo $nationality; 
} 
?> 
    <!DOCTYPE html> 
<html lang="en"> 

<head> 

</head> 

<body> 
    <form method="POST"> 

      <?php if(isset($_GET['id'])) { ?> 
      <input type="hidden" name="act" value="edit"/> 
      <input type="hidden" name="id" value="<?php echo $id; ?>"/> 

      <?php } else{ ?> 
      <input type="hidden" name="act" value="add"/> 
      <?php } ?> 

                       <label> FirstName</label> 

<input type="text" name="firstname" value="<?php echo @$firstname; ?>"><br> 

    <label> LastName</label> 

<input type="text" name="lastname" value="<?php echo @$lastname; ?>"><br> 

<label> Nationality</label> 

<input type="text" name="nationality" value="<?php echo @$nationality; ?>"><br> 

<a href="demo2.php"> <input type="button" id="next" name="next" value="next" > 

<?PHP $_SESSION["firstname"] = "Preethi"; 
                  $_SESSION["lastname"] = " Rajan"; 
                  $_SESSION["nationality"] = "Indian"; ?>  
</form> 

</body> 

</html> 

demo2.phpです

<?php 
session_start(); 
if($_POST) 

    { 
     if($_POST['act'] == "add") 

    {          

     $firstname= $_SESSION['firstname']; 
     $lastname= $_SESSION['lastname']; 
     $nationality= $_SESSION['nationality'];   

     $mobileno = $_POST['mobileno']; 

     $email = $_POST['email']; 

     $commaddr = $_POST['commaddr']; 

     $city = $_POST['city']; 

     $pincode = $_POST['pincode']; 

     $state = $_POST['state']; 

     $permaddr = $_POST['permaddr']; 

     $conn = mysql_connect("localhost","root",""); 
     $db = mysql_select_db("reg",$conn); 

    $sql = "INSERT INTO registration (firstname,lastname,nationality,mobileno,email,commaddr,city,pincode,state,permaddr) VALUES ('".$_SESSION["firstname"]."','".$_SESSION["lastname"]."' ,'".$_SESSION["nationality"]."', '".$mobileno."' , '".$email."' , '".$commaddr."','".$city."','".$pincode."','".$state."','".$permaddr."')"; 

    $rep = mysql_query($sql); 
    } 
} 

    ?> 
    <!DOCTYPE html> 
<html lang="en"> 

<head> 
</head> 
    <form action="demo2.php" method="POST"> 

<?php if(isset($_GET['id'])) { ?> 
      <input type="hidden" name="act" value="edit"/> 
      <input type="hidden" name="id" value="<?php echo $id; ?>"/> 

      <?php } else{ ?> 
      <input type="hidden" name="act" value="add"/> 
      <?php } ?> 
<label> Mobile Number</label> 

<input type="text" name="mobileno" value="<?php echo @$mobileno; ?>"><br> 

<label> E Mail ID</label> 

<input type="text" name="email" value="<?php echo @$email; ?>"><br> 

<label> Communication Address</label> 

<input type="text" name="commaddr" value="<?php echo @$commaddr; ?>"><br> 

<label> City</label> 

<input type="text" name="city" value="<?php echo @$city; ?>"><br> 

<label>Pin Code</label> 

<input type="text" name="pincode" value="<?php echo @$pincode; ?>"><br> 

<label>State</label> 

<input type="text" name="state" value="<?php echo @$state; ?>"><br> 

<label> Permanent Address</label> 

<input type="text" name="permaddr" value="<?php echo @$permaddr; ?>"><br> 

<input type="submit" name="submit" value="submit" style="height:50px; width:150px"> 

</form> 
</body> 

</html> 

答えて

2

でアンカータグのコードに置き換えます

demo2.phpオン
<a href="demo2.php?firstname=<?php $_POST['firstname'] ?>&lastname=<?php $_POST['lastname'] ?>&nationality=<?php $_POST['nationality'] ?>"> <input type="button" id="next" name="next" value="next" ></a> 

を:

$fname = $_GET['firstname']; 
$lname = $_GET['lastname']; 
$nationality = $_GET['nationality']; 
+0

卿は、まだ私は未定義のインデックスFIRSTNAME、姓や国籍などのエラーメッセージを取得メートル。私はこの問題を解決するのに役立ちます。 –

+0

更新された答えを試してください@PreethiRajan – Nabeel

+0

Sir、私は次のエラーを受け取りました: (!)注意:未定義のインデックス:firstnameはC:\ wamp \ www \ siruthuli \ pages \ demo1.php on line 70コールスタック#TimeMemoryFunctionLocation 10.0007145704 {main}().. \ demo1.php:0&lastname = 注意:未定義インデックス:C:\ wir \ www \ siruthuli \ pages \ demo1の姓ライン70 コールスタック #\t時間\tメモリー\t機能\t場所 0.0007 {メイン}()\t上の.php .. \ demo1.php:0 &国籍= のNotI(!) CE:未定義のインデックス:Cでの国籍:\ WAMP \ WWW \ siruthuliページは、ライン70 コールスタック #\t時間\tメモリー\t機能\t場所にdemo1.php \ \ 0.0007 )\t({メイン} .. \ demo1.php:0 –

関連する問題