2013-12-12 74 views
0

如何在不使用表單的情況下將數據從一個頁面發送到另一個頁面? 我得到的ID和類型由GET方法將數據從一個頁面發送到另一個頁面而不使用表單php

<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="[email protected]"/><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和類型的我在表單頁面獲得的網址我怎樣才能去做?

+1

我看到的'mysql_query'這兩者都是不好的直列造型和用法網頁設計實踐。我認爲你現在應該關心那些人。 – samayo

+0

您的代碼提供了一個如何構造危險的SQL查詢的絕佳示例。 http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – Dave

+0

是你兩個權利,但下一次我肯定不會這樣做設計 – shani

回答

0

您需要添加&type=

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

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

您需要form.php的

<?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使用$_GET

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

我這樣做,但它在數據庫中插入coloumn類型的id值,當添加新記錄時,id爲0 ..在formsubmitted.php中使用 – shani

+0

,使用print_r($ _ POST);驗證發佈的值 –

+0

它不顯示任何結果..幫助..! – shani

0

您可以發送該PARAMS在一個隱藏字段作爲這個:

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

而且你需要增加保護,防止XSS

相關問題