Is it possible to check if two variables are defined in an easier way?

-3

I get the form via POST the sd and video fields, needing to verify that both are set. I currently do the following:

<?php

if (isset($_POST['sd'])) {

    $sd = $_POST['sd'];

    if (isset($_POST['video'])) {

        // ...

    }

}

Can you make this check simpler?

    
asked by anonymous 20.07.2018 / 21:57

1 answer

2

The isset accepts several parameters, like this:

if(isset($_POST['sd'], $_POST['video'])){

    $sd = $_POST['sd'];

    $vid = $_POST['video'];


    $sql = "UPDATE 'player' SET 'sd' = '$sd', 'video' = '$vid' WHERE 'id' = 3";
    $ssl = mysqli_query($conn, $sql);

    $_SESSION['post'] = 'Configuração salva com sucesso!';
    header("Location: edit.php");

    exit();

}

Just to note, I recommend that you use mysqli_real_escape_string to avoid SqlInjection, like this:

if(isset($_POST['sd'], $_POST['video'])){

    $sd = mysqli_real_escape_string($_POST['sd']);

    $vid = mysqli_real_escape_string($_POST['video']);


    $sql = "UPDATE 'player' SET 'sd' = '$sd', 'video' = '$vid' WHERE 'id' = 3";
    
20.07.2018 / 22:13