duanmei1930 2016-07-05 08:58
浏览 86
已采纳

在php中获取文本框的值从1表单到另一个表单

I am trying to get the value from 1 form to another in php. In form1 there r fields such as name,email etc. After the submitting the form it goes to another form where name,email value as to display from the form1. But in my form name,email doesnt display in form2. Here is the code.

form1.php

  <form method="post" name="XIForm" id="XIForm" action="registration.php">
        <p><label>Name</label><br/><input type="text" name="fname" id="fname" value="" style="margin-left:30px;" placeholder="Name"></p>
        <p><label>Email</label><br/><input type="text" name="email" id="email" value="" style="margin-left:30px;" placeholder="Email"></p>

<?php
    include_once 'db.php';
  if(isset($_POST['XISubmit'])) {

         $fname= mysql_real_escape_string($_POST['fname']);
        $email=$_POST['email'];
        $check_email="select * from reg where email='$email'";
        $run1=mysql_query($check_email);

        if(mysql_num_rows($run1)>0){
        echo "<script>alert('email already exits in our database. Please try with Another!')</script>";
        exit(0);
        }
     else{
              $query = "INSERT INTO reg(fname,username,password,cpassword,email) VALUES ('$fname','$username','$password', '$cpassword','$email')";
              $run11=mysql_query($query);
    $to=$_POST['email'];         
   if($run11){
    $_SESSION['sess_user4']=$username;
    echo "<script>alert('Registration Successful')</script>";
    echo "<script>window.open('attachfile.php', '_self')</script>";
    }
    }   
    }
    ?>   

Form2.php

<form method="post" name="XIForm" action="attach.php" enctype="multipart/form-data" onSubmit="return validate();">
  <h4 style="color:#6f4617;margin-left:10px;font-size:15px;font-family:Book Antiqua;color:#168eb6">&nbsp;&nbsp;<b>Welcome <?=$_SESSION['sess_user4']?>  </b>
<br/>

<label>Confirm Name</label><br/>
<input type="text" name="name1" id="name1" style="margin-left:30px;" placeholder="Name" value="<?php if(isset($_GET['fname'])) { echo $_GET['fname']; } ?>"  />
<br/><br/>
  • 写回答

2条回答 默认 最新

  • duangouhui0446 2016-07-05 09:12
    关注

    try this or more PHP Header Location with parameter

    //after submitting form
    header("Location: form2.php?fname=".$fname);
    //then
     isset($_GET['fname']){
            echo $fname;
    
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码