2014-01-21 48 views
0

有沒有辦法讓$_POST['msg'](其中name =「味精」從形式過來)是$_POST[$newstring](其中$newstring = $string;$string = $_POST['msg'];

$_POST[$newstring]不起作用。有沒有把一個變量的方式在$_POST[]

我真的希望得到一個具體答案這個具體的問題我想要完成的只是從一個窗體傳入一個變量到$_POST[]我在尋找直接的答案,是或否

如果是,如何格式化它(例如$_POST[$variable]$_POST['$variable']$_POST["$variable"]或其他某種方式)。

+1

你想要什麼我不明白,但它聽起來像是你打開自己的安全問題......讓我們在這裏明確:帶有** name **的表單元素髮布到腳本的方法=「post」'將在該腳本中可用'$ _POST'超全球。在表單文章中對'$ _POST'進行一些基本的調試,看看你得到了什麼,然後處理它,或者給我們一些你想要的具體例子。 –

回答

2
$_POST['newstring'] = $_POST['msg']; 

請記住,$ _POST是通過HTTP POST方法傳遞的變量的關聯數組。但是像任何數組一樣,您可以像這樣修改它:

$arr[key] = value; 

其中key是一個字符串或整數。關於PHP數組的更多信息可以在這裏找到:http://au1.php.net/manual/en/language.types.array.php

0

您可以從$ _POST讀取/分配任何數組的方式,因爲在功能上它是一個關聯數組。

$string = $_POST['msg']; 
$newstring = 'this is the new value'; 
$_POST['msg'] = $newstring; 
0

嘗試使用Ajax將數據表單yore HTML文件傳遞給php。

在HTML部分:

  Call a function with this parameter with message containing html element. 

     <input type="textbox" name="msg" onclick="post_msgto_php(this)"> 

腳本

 In the script part define the post_msgto_php(this) function with a Ajax post type to your php. 

     try this .js code: 

     function post_msgto_php(my_msg) 
       { 
       var msg=my_msg.name; 
       $.ajax({ 
        type: "POST", 
        url: "your_post_msg.php" 
        data:{msg:msg},            
        dataType:'JSON', 

        success:function(data){ 

           if(data.response=="success") 

           } 
       }); 
       } 

your_post_msg.php:

   Here send back a json response=>success usig json_encode() 

       <?php 



        $_POST['newstring'] = $_POST['msg']; 

        $data=array("response"=>"success"); 
        json_encode($data); 




       ?> 
相關問題