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]

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题