6
I need to save the fruits and values in different fields in the bank"
PHP:
<?php
session_start();
//if (!isset($_SESSION["usuario"])){echo "<script>alert('O SEU INGRESSO É VALIDO');window.location=\"index.php\";</script>";}
include "funciones.php";
date_default_timezone_set("America/Sao_Paulo");
if (isset($_POST["edit_fruta_x"])){
$_SESSION["idrelatorio"]=$_POST["relatorio"];//Se o usuário escolheu da lista um projeto para diagnosticar, guardo o seu IDprojeto para referenciar
$_SESSION["idbanca"]=$_POST["banca"];
$_SESSION["idfruta"]=$_POST["fruta"];
unset($_POST["fruta"]);
lerbanca($_SESSION['idbanca']);//procura os dados da banca escolhida
lerlocalizacao($_SESSION["idrelatorio"]);
}
else{
$_SESSION["idrelatorio"]=$_POST["relatorio"];
$_SESSION["idbanca"]=$_POST["banca"];
lerlocalizacao($_SESSION["idrelatorio"]);
unset($_SESSION['idfruta']);
unset($_SESSION['fruta']);
}
?>
HTML:
<script type="text/javascript">
}
</script>
</head>
<body>
<form class="form-signin" action='salvafrutas.php' method="post">
<label>bancas de frutas</label>
<!-- 1.1 salvar frutas -->
<label>1. Lista de Frutas</label>
<table>
<!-- lista que seleciona as ações do botão para saber se está marcado ou não-->
<tr><th colspan=3><b>1.Tipo de frutas</b></th></tr>
<tr><th colspan=2>Características</td><th colspan=2>valores</th></tr>
<tr><td colspan=2>1. uva</td><td><input id="uva" type="checkbox" name="comportamento[]" value="6" <?php if(isset($_SESSION['comportamento'])){echo (strpos($_SESSION['comportamento'],'6')!==false) ? 'checked="checked"' : '';}?> onclick="apaga_nao1(this)"> 6 </td></tr>
<tr><td colspan=2>2. banana</td><td><input id="banana" type="checkbox" name="comportamento[]" value="0" <?php if(isset($_SESSION['comportamento'])){echo (strpos($_SESSION['comportamento'],'0')!==false) ? 'checked="checked"' : '';}?> onclick="apaga_nao1(this)"> 0 </td></tr>
<tr><td colspan=2>3. maça</td><td><input id="maça" type="checkbox" name="comportamento[]" value="3" <?php if(isset($_SESSION['comportamento'])){echo (strpos($_SESSION['comportamento'],'3')!==false) ? 'checked="checked"' : '';}?> onclick="apaga_nao1(this)"> 3 </td></tr>
<tr><td colspan=2>4. pera</td><td><input id="pera" type="checkbox" name="comportamento[]" value="4" <?php if(isset($_SESSION['comportamento'])){echo (strpos($_SESSION['comportamento'],'')!==false) ? 'checked="checked"' : '';}?> onclick="apaga_nao1(this)"> 4 </td> </tr>
</table>
<br>
<!--<button class="btn btn-lg btn-primary btn-block" type="submit">Salvar</button> -->
<input id='btgravar' type='image' src="salvar.png" title='SALVAR' width='70' height='70'/>
</form>
</body>
</html>
Good, it was clearer! I’ve already given my vote to reopen. What do you want to save in the comic? When you have in HTML
name="comportamento[]"
this will cause PHP to reach an array where it has values fromvalue
HTML. That is, if someone chooses all the checkboxes they will have something likearray(6, 0, 3,4);
, is that what you want to keep in the comic book or do you want the name of the fruit too? You can explain better all the information you want to save in the comic book of that form?– Sergio
You need to make an array with the name of the fruits, linked to the code you assigned in the value of your select html. Example: $fruits = array(0=>"banana", 3=>"maca", 4=>"pera", 6=>"grape"); $nomedafruta = $fruits[$_POST["behavior"]; (just example, it is necessary to foreach $_POST["behavior"] in order to get all the marked...)
– Marcelo Gomes
So @Marianagomes - Inside the foreach, if you’ve done the $fruit array like I said (declare at the beginning of your php), you’ll have the fruit with $fruit[$value]... If you want content separated by /, you need to do: $comporta['comportamento'] .= $value.":". $fruit[$value]." /"; Thus Voce will have the selected number, two points (:), and the name of the fruit, followed by a bar (/).
– Marcelo Gomes
Good morning Mariana, can you answer my question/comment above?
– Sergio
@Sergio, I need to save the fruits and values, but in different fields in the database.
– Mariana Gomes