不使用表单php将数据从一个页面发送到另一个页面

时间:2013-12-12 17:36:35

标签: php

如何在不使用表单的情况下将数据从一个页面发送到另一个页面? 我正在通过 GET 方法

获取ID和类型
 <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."; }

     ?>

我想在表单页面的网址中插入我得到的ID和类型,我该怎么办?

2 个答案:

答案 0 :(得分:0)

您需要添加&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']; ?>

答案 1 :(得分:0)

您可以在隐藏字段中发送此参数:

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

您需要添加针对XSS的保护