admin管理员组

文章数量:1389799

I'm trying to sanitize some arrays received through $_POST[] and insert them into database. How should I do that?

The html is name="room_types[]"

$room_types = $_POST['room_types'];

how to sanitize this array?

I'm trying to sanitize some arrays received through $_POST[] and insert them into database. How should I do that?

The html is name="room_types[]"

$room_types = $_POST['room_types'];

how to sanitize this array?

Share Improve this question asked Feb 18, 2020 at 7:39 dragos.nicolaedragos.nicolae 134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use array_map like this:

$room_types = isset( $_POST['room_types'] ) ? (array) $_POST['room_types'] : array();

$room_types = array_map( 'esc_attr', $room_types ); // Replace esc_attr with your desire sanitization

本文标签: databasesanitize POST arrays