【问题标题】:submit a form values to another page in php and inserting values from the new page将表单值提交到 php 中的另一个页面并从新页面插入值
【发布时间】:2014-05-01 12:25:44
【问题描述】:

我在php 中有一个用户注册表单usertype。提交后,我希望表单将其值带到另一个页面 user_med.php 并且从这个页面我需要在表格中输入值

这里是代码

<html>
<body>
<form id="usertype" action="user_med.php " method="get" >
  <center>
    <h1> User Registration Page </h1>
    <div id="content">
      <input type="hidden" id="userreg" name="userreg" value="type" />
      <ul class="user">
        <li class="label">User id </li>
        <li class="field">
          <input type="text" id="userid" name="userid" class="required error"/>
        </li>
      </ul>
      ..........
      <input type="submit" name="submit" value="Submit"/>
    </div>
  </center>
</form>
</body>
</html>

【问题讨论】:

  • method=postmethod=get
  • 那么到现在你做了什么?也向我们展示代码 -_-
  • 用户注册页面

    • 用户id
    ....

标签: php


【解决方案1】:

示例:

go1.php

<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{  
 $_SESSION['name1']=$_POST['username'];
 header("Location: go2.php");
}
?> 


<form action="#" onsubmit="" method="post">   
<b>Enter your name: </b>
<br> 
<input type="text" name="username">
<br> 
<input type="submit" value="submit" >
</form>

go2.php

<?php
session_start();

echo "Result:<br>";
echo $_SESSION['name1'];

echo'<br><a href="go1.php">Go back</a>';

?>

【讨论】:

  • 在你的情况下: $userid = $_POST["userid"];将是:$_SESSION['name1'] = $_POST["userid"];
  • "; echo "userid :".$userid ."
    " ; echo "empname :".$empname."
    " ; echo "username:".$username."
    " ; echo "密码:".$password ."
    "; echo "状态:".$radiobt."
    " ; echo "doa:".$doa ."
    "; echo "createdby:".$createdby."
    "; ?>
  • 使用了上面的代码,但它没有输出值。
  • 未定义索引:第 4 行 C:\wamp\www\cast\user_med.php 中的用户类型
  • 我已经放置了一个新的示例代码,带有表单和结果页面。 stackoverflow.com/a/22604863/3437255
【解决方案2】:

您可以将表单操作赋予不同的页面

<form action="user_med.php">
</form>

或者你可以使用 jquery $.ajax

<script type="text/javascript">
//#usertype will be the form id
$('#usertype').submit(function(){
$.ajax({
            type: 'POST',
            url: 'user_med.php',
            data: $("#usertype").serialize(),
            success:function(data, status)
            {
                alert(data);
                //Do success action here...
            }
        });
});
</script>

【讨论】:

  • 如何显示 user_med.php 中的值
  • 你可以使用 $_post['form_field_name'];
【解决方案3】:

创建一个会话变量并将值移动到它 $_SESSION['name1']=$数据 $_SESSION['name2']=$data .....

在下一页开始会话 session_start();

然后从上面创建的会话变量中检索值

回声 $_SESSION['name1']; ....

【讨论】:

    【解决方案4】:

    您可以使用以下内容:-----

    <form action="user_med.php" method="post">
    </form>
    

    "user_med.php" 页面上,您可以使用以下语法获取表单的所有值:--

    $var=$_POST['field_name'];
    

    然后您可以将所有值插入到表中...

    希望对你有帮助。

    【讨论】:

    • "; echo "userid :".$userid ."
      " ; echo "empname :".$empname."
      " ; echo "username:".$username."
      " ; echo "密码:".$password ."
      "; echo "状态:".$radiobt."
      " ; echo "doa:".$doa ."
      "; echo "createdby:".$createdby."
      "; ?>
    • 未定义索引:第 4 行 C:\wamp\www\cast\user_med.php 中的用户类型
    • 我认为某些字段名称不匹配
    猜你喜欢
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 2021-11-13
    • 2021-06-06
    • 2020-10-22
    相关资源
    最近更新 更多