dqys98341
2017-06-22 15:28
浏览 39
已采纳

数组中的PHP数组在数组$ _POST中

I have a question about displaying a variable that is in the an array of another array. Below is an example of a var_dump() of my $_POST variable. As you can see I have an array.. and another array in that array.. and another array in that array.. I actually need a variable from each of the layers.

Array(
[type] => note
[date_time] => 17-01-01
[initiated_from] => admin
[initiated_by] => admin
[list] => 0
[note] => THIS IS A TEST 
[contact] => Array
    (
        [id] => 250
        [email] => TEST@TESTING.COM
        [first_name] => TEST
        [last_name] => McTESTER
        [phone] => (777)777-7777
        [ip] => 0.0.0.0
        [tags] => buyer, requote, followup1, delete
        [fields] => Array
            (
                [3] => TESTER@TESTER.com
                [5] => TESTING TESTER
                [10] => STATE
                [11] => CITY
                [12] => COUNTY
                [6] => PHONE NUMBER
                [8] => www.test.com
                [9] =>  MORE TESTS
            )

Here is my code that I tried.

$sql_note="INSERT INTO customer_notes(customer_email,note,added_by,note_date) VALUES('$_POST[contact][email]','$_POST[note]','$_POST[contact][fields][3]','$note_date')";

(Ignore the $note_date) So these are the three things I am trying to get..

$_POST[note]

$_POST[contact][email]

$_POST[contact][fields][3]

I get the first one just fine but I get ARRAY[EMAIL] and ARRAY[FIELDS][3]

图片转代码服务由CSDN问答提供 功能建议

我有一个关于显示另一个数组的数组中的变量的问题。 下面是我的 $ _ POST 变量的 var_dump()的示例。 你可以看到我有一个数组...和该数组中的另一个数组..和该数组中的另一个数组..我实际上需要每个层中的一个变量。

 数组(
 [type] => note 
 [date_time] => 17-01-01 
 [initiated_from] => admin 
 [initiated_by] => admin 
 [list] =&gt  ; 0 
 [注意] =>这是测试
 [联系] =>数组
(
 [id] => 250 
 [email] => TEST@TESTING.COM 
  [first_name] => TEST 
 [last_name] => McTESTER 
 [phone] =>(777)777-7777 
 [ip] => 0.0.0.0 
 [tags] =>买家 ,requote,followup1,delete 
 [fields] =>数组
(
 [3] => TESTER@TESTER.com 
 [5] => TESTING TESTER 
 [10] =>状态 
 [11] => CITY 
 [12] => COUNTY 
 [6] =>电话号码
 [8] => www.test.com 
 [9] =>更多 测试
)
   
 
 <  p>这是我尝试的代码。 
 
 
  $ sql_note =“INSERT INTO customer_notes(customer_email,note,added_by,note_date)VALUES('$ _ POST [contact] [email  ]”, '$ _ POST [注]', '$ _ POST [接触] [领域] [3]', '$ note_date')“; 
   
 
 

( 忽略 $ note_date )所以这些是我想要的三件事......

  $ _ POST [note] 
 
 $ __ $  [联系方式] [电子邮件] 
 
 $ _POST [联系方式] [字段] [3] 
   
 
 

我得到第一个就好了,但我得到了 ARRAY [EMAIL] ARRAY [FIELDS] [3]

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxi7722 2017-06-22 15:37
    已采纳

    You are using variable expansion incorrectly:

    $foo = array();
    $foo['one']['two'] = 'OK';
    
    echo "Value is $foo[one][two]
    "; // Value is Array[two]
    echo "Value is {$foo[one][two]}
    "; // Value is OK
    

    ... and in the wrong job. Your query should look like this:

    $sql_note = "INSERT INTO customer_notes(customer_email, note, added_by, note_date)
        VALUES (?, ?, ?, ?)";
    

    ... and values should be passed in an array. Injecting raw untrusted data into SQL code is terribly messy to write and leads to SQL injection vulnerabilities. Please check the documentation for your database library.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题