1
The registered items have various flavors, chocolate, strawberry, vanilla, etc, and each is inserted by select multiple
in the register, it is saved as "chocolate" but the other selected flavors are not inserted.
PHP code
if ( ! isset( $_POST ) || empty( $_POST ) ) {
echo '.';
echo '<script>';
echo "Materialize.toast('Impossível continuar!', 4000, 'rounded black');";
echo '$(".success_v2").removeClass("more");
$(".success_v2").removeClass("auth");
$(".loader").hide();
</script>';
exit;
}
foreach ( $_POST as $chave => $valor ) {
$$chave = $valor;
if ( empty( $valor ) ) {
echo '.';
echo '<script>';
echo "Materialize.toast('Existe campo em branco', 4000, 'rounded red');";
echo '$(".success_v2").removeClass("more");
$(".success_v2").removeClass("auth");
$(".loader").hide();
</script>';
}
}
if (
! isset( $nome )
|| ! isset( $marca )
|| ! isset( $categoria )
|| ! isset( $peso )
|| ! isset( $sabor )
|| ! isset( $prod_destaque )
|| ! isset( $preco )
|| ! isset( $codigo )
|| ! isset( $prod_desconto )
|| ! isset( $dob )
) {
echo '.';
echo '<script>';
echo "Materialize.toast('Ainda há campos vázios.', 4000, 'rounded red');";
echo '$(".success_v2").removeClass("more");
$(".success_v2").removeClass("auth");
$(".loader").hide();
</script>';
exit;
}
$prepara = $conexao_pdo->prepare("INSERT INTO `produtos` (`nome`,`nome_iso`,`cod`,`marca`,`categoria`,`status`,`preco`,`desconto`,`data`,`chns`,`autor`,`descricao`,`peso`,`sabores`,`cover`,`prod_destaque`,`prod_desconto`,`link`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$verifica = $prepara->execute(
array(
$nome,
$nome_cl,
$codigo,
$marca,
$categoria,
$dob,
$preco,
$desconto,
$data,
$chns,
$autor,
$descricao,
$peso,
$sabor,
$novo_nome_imagem,
$prod_destaque,
$prod_desconto,
$link_final
)
);
HTML
<select class="seleciona" name="sabor" multiple="">
<option disabled selected>Selecione o Sabor</option>
<option value="chocolate">chocolate</option>
<option value="morango">morango</option>
<option value="baunilha">baunilha</option>
</select>
Man, everything helped me a lot. But I’m just having trouble with the serialize and unserialize, I don’t know much of php, but what I do know I can manage. If you don’t mind, could you give me an example of this serialize or unserialize for select?
– Thomas Franklin
@Thomasfranklin edited the answer to add this example.
– Juven_v
thanks for the explanation, I will study better the use of how to use the return of the serialize/unserialize when it gets more relaxed over time. I made a really crazy code that worked using
explode
, arrayoffset
andif
.– Thomas Franklin