Is my php code safe?

I want to ask you if my PHP code is safe enought. I don’t know if i should escape special characters in string after regex validation:


require_once '../../../wp-load.php';

$errors = [];

if (preg_match('/[^a-ząćęółśżźń ]/i', $_POST['name']) || strlen(trim($_POST['name'])) == 0 || strlen($_POST['name']) > 60) {
    $errors[] = "Invalid name";

if (empty($errors)) {
    echo json_encode(['status' => true]);
    $wpdb->query($wpdb->prepare("INSERT INTO people VALUES(null, %s)", $_POST['name']));
} else {
    echo json_encode(['status' => false, 'errors' => $errors]);

Source: sql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.