繁体   English   中英

在不使用表单php的情况下将数据从一页发送到另一页

[英]Sending Data from one page to another without using form php

如何不使用表单将数据从一页发送到另一页? 我正在获取ID并通过GET方法输入

 <a href="form.php?id=<?php echo $_GET['id']."&".$_GET['type']; ?>" class="orderbtn">Order Now</a>

当我进入form.php时 ,我填写表单并单击提交按钮,我的表单页面代码如下

form.php

<div id="form">
  <p class="rf">*Required Fields </p>
  <form action="formsubmitted.php" onsubmit="return formValidate()" method="post" name="myform">
         <span class="required" title="Required Field">*</span>
         <span style="font-size:16px; color:#000; font-family:Arial, Helvetica, sans-serif;">Name: </span>  
         <input id="name" title="Enter Your Full Name" type="text" name="name" autofocus="autofocus" required="required" value=""/><br/>
          <span class="required" title="Required Field">*</span>
         <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;padding-right:10px;">Email:</span> 
         <input id="email" type="email" name="email" required="required" placeholder="xyz@example.com"/><br/>
          <span class="required" title="Required Field">*</span>
         <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;">Address:</span>
         <input id="address" title="Enter Address" type="text" name="address" required="required" value=""/><br/>
         <span class="required" title="Required Field">*</span>
         <span style="font-size:16px;color:#000; font-family:Arial, Helvetica, sans-serif;">Contact Number:</span>
         <input id="contactno"  title="Enter Number" type="text" name="contact" required="required" value=""/><br/>
         <input id="submit" name="submit" type="submit" value="Submit"/></span>
   </form> 
</div>

当我提交时,它进入formsubmitted.php页面,在那里我使用post方法将数据插入数据库

formsubmitted.php

   <?php
    $connection = mysql_connect("localhost","root","");
        $select_db = mysql_select_db("fashion",$connection);
        if(!$connection)
        {
            die ("Could not Connect".mysql_error());
        }

         $query = "INSERT INTO `order` (flname,email,address,contact) VALUES ('{$_POST['name']}','{$_POST['email']}','{$_POST['address']}','{$_POST['contact']}');";
     echo $query . "<br />";
     $res = mysql_query($query,$connection);
     if(!$res) {die("Could Not Enter Data".mysql_error());}
     else { echo "Enter Data Successfully."; }

     ?>

我想在表单页面的URL中插入要获取的ID和类型,我该怎么做?

您需要添加&type=

 <a href="form.php?id=<?php echo $_GET['id']."&type=".$_GET['type']; ?>" class="orderbtn">Order Now</a>

................................................... .................................................................. ^

您需要使用form.php中的$_GET

 <?php   $id = $_GET['id'];
         $type = $_GET['type'];
  ?>

     <form action="formsubmitted.php" onsubmit="return formValidate()" method="post" name="myform">
    ......
      <input name="id" type="hidden" value="<?php echo $id;?>">
      <input name="type" type="hidden" value="<?php echo $type;?>">
    </form>

在formsubmitted.php中:

 <?php echo $_POST['id']; echo $_POST['type']; ?>

您可以在隐藏字段中发送此参数,如下所示:

<input type="hidden" name="type" id="type" value="<?php echo $_GET['type'];?>"/>

而且您需要添加针对XSS的保护

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM