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.

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮