Currently I am working on a pop-up window and I have it in the following way
It is assumed that this is the update view, for which said user has already registered his information before, now I would like to know how I do it so that in my checkbox I can check all the ones that he selected when registering. At the moment I do not have a written code because I have not known how to start.
This opens the pop-up window:
function alerta() {
new $.Zebra_Dialog('<strong>Actualizacion del Usuario</strong><br><br>', {
'source': {'ajax': 'perfil/actualizar.php?nickP=<?php echo "$nick2" ?>'},
width: 1000,
buttons: false,
animation_speed_show: 3000,
animation_speed_hide: 3000,
'title': 'Actualizar'
});
}
And the form is currently in this way:
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "proyecto_terror";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$nick2 = $_GET["nickP"];
$sql = "SELECT * FROM usuario WHERE nick = '" . $nick2 . "'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$datos = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$datos[] = $row;
?>
<div id="alerta" style="width: 100%;height: 100%; ">
<form id="formularin" method="POST" action="perfil/Update.php"><center><table class="formulario" id="tabla" >
<tr>
<td><center><label >Nombre: </label></center></td>
<td><input onkeypress="sololetras()" id="nombre" class="cajaTexto" value="<?php echo $row["nombre"]; ?>" name="nombre" type="text"></td>
</tr>
<tr>
<td><center><label >Nick:</label></center></td>
<td><input maxlength="20" id="nick" class="cajaTexto" value="<?php echo $row["nick"]; ?>" name="nick" type="text"></td>
</tr>
<tr>
<td><center>Cumpleaños: </center></td>
<td>
<span style="margin-left: 20px;margin-right: 10px;"> Dia: </span> <select name="dia" class="selector" id="dia">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
<span style="margin-left: 20px;margin-right: 10px;"> Mes: </span><select name="mes" class="selector" id="mes">
<option value="01">Enero</option>
<option value="02">Febrero</option>
<option value="03">Marzo</option>
<option value="04">Abril</option>
<option value="05">Mayo</option>
<option value="06">Junio</option>
<option value="07">Julio</option>
<option value="08"> Agosto</option>
<option value="09">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
</select>
<span style="margin-left: 20px;margin-right: 10px;"> Año: </span><input name="ano" class="spinnerT" id="ano" TYPE="NUMBER" MIN="1950" MAX="2006" STEP="1" VALUE="2000">
</td>
</tr>
<tr>
<td><center><label >Edad: </label></center></td>
<td><input class="spinnerT" value="<?php echo $row["edad"]; ?>" id="edad" name="edad" TYPE="NUMBER" MIN="10" MAX="66" STEP="1" VALUE="20"></td>
</tr>
<tr>
<td><center><label >Sexo: </label> </center></td>
<td><div class="radio">
<?php
if ($row["sexo"] == "hombre") {
?>
<input type = "radio" name = "sexo" value = "hombre" checked = "checked" id = "hombre">
<label for = "hombre" >Hombre</label>
<input type="radio" name="sexo" value="mujer" id="mujer">
<label for="mujer">Mujer</label>
<?php
} else {
?>
<input type = "radio" name = "sexo" value = "hombre" id = "hombre">
<label for = "hombre" >Hombre</label>
<input type="radio" name="sexo" value="mujer" checked = "checked" id="mujer">
<label for="mujer">Mujer</label>
<?php
}
?>
</div>
</tr>
<tr>
<td><center><label >Intereses: </label></center></td>
<td>
<div class="checkbox">
<table >
<tr>
<td> <input value="Asesinos" type="checkbox" id="checkbox1" name="checkbox[]"><label for="checkbox1" style="margin-right: 10px;">Asesinos</label>
</td>
<td> <input value="Misterios" type="checkbox" id="checkbox2" name="checkbox[]" ><label for="checkbox2" style="margin-right: 30px;">Misterios</label>
</td>
<td> <input value="Creppys" type="checkbox" id="checkbox3" name="checkbox[]" ><label for="checkbox3" style="margin-right: 10px;">Creppys</label>
</td>
</tr>
<tr>
<td> <input value="Ovnis" type="checkbox" id="checkbox4" name="checkbox[]" ><label for="checkbox4" style="margin-right: 35px;">Ovnis</label>
</td>
<td> <input value="Enfermedades" type="checkbox" id="checkbox5" name="checkbox[]" ><label for="checkbox5" style="margin-right: -10px;">Enfermedades</label>
</td>
<td> <input value="Leyendas" type="checkbox" id="checkbox6" name="checkbox[]" ><label for="checkbox6" style="margin-right: 10px;">Leyendas</label>
</td>
</tr>
<tr>
<td> <input value="Fantasmas" type="checkbox" id="checkbox7" name="checkbox[]" ><label for="checkbox7" style="margin-right: -5px;">Fantasmas</label>
</td>
<td> <input value="Conspiraciones" type="checkbox" id="checkbox8" name="checkbox[]" ><label for="checkbox8" style="margin-right: -13px;">Conspiraciones</label>
</td>
<td> <input value="Deep-Web" type="checkbox" id="checkbox9" name="checkbox[]" ><label for="checkbox9" style="margin-right: 10px;">Deep Web</label>
</td>
</tr>
</table>
<br>
</div>
</td>
</tr>
<tr>
<td colspan="2"><center><button id="btnsave" style="margin-right: 20px;text-decoration: none;">Guardar<img src="../Imagenes/images/ICO/Mask 2.ico" style="width:20px;height: 20px;margin-top: -1px;margin-left: 3px;"></button>
<button type="reset" id="btncancelar" >Cancelar<img src="../Imagenes/images/ICO/Jack O Lantern.ico" style="width:20px;height: 20px;margin-top: -1px;float: right;margin-right: 5px;"></button></center></td>
</tr>
</table></center></form>
<?php
}
}
mysqli_close($conn);
?>
</div>
</body>
In this way the interest is saved, which in this case would be the checkbox
:
if ($_POST['checkbox'] != "") {
if (is_array($_POST['checkbox'])) {
while (list($key, $value) = each($_POST['checkbox'])) {
if ($contador == 0) {
$registro1 = $_POST['checkbox'][0];
$registro2 = "";
$registro3 = "";
$registro4 = "";
$registro5 = "";
$registro6 = "";
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 1) {
$registro2 = $_POST['checkbox'][1];
$registro3 = "";
$registro4 = "";
$registro5 = "";
$registro6 = "";
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 2) {
$registro3 = $_POST['checkbox'][2];
$registro4 = "";
$registro5 = "";
$registro6 = "";
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 3) {
$registro4 = $_POST['checkbox'][3];
$registro5 = "";
$registro6 = "";
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 4) {
$registro5 = $_POST['checkbox'][4];
$registro6 = "";
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 5) {
$registro6 = $_POST['checkbox'][5];
$registro7 = "";
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 6) {
$registro7 = $_POST['checkbox'][6];
$registro8 = "";
$registro9 = "";
$contador++;
} else if ($contador == 7) {
$registro8 = $_POST['checkbox'][7];
$registro9 = "";
$contador++;
} else if ($contador == 8) {
$registro9 = $_POST['checkbox'][8];
}
}
}
$cadena = $registro1 . " " . $registro2 . " " . $registro3 . " " . $registro4 . " " . $registro5 . " " . $registro6 . " " . $registro7 . " " . $registro8 . " " . $registro9;
mysql_query("insert into usuario(nombre,nick,password,fecha_nac,edad,sexo,intereses,fecha_reg) values ('$nombre','$nick','$password','$cumpleano','$edad','$sexo','$cadena','$fechaR')");
And that's how they are stored in the database:
Now there is only one interest, but if you add more, they are assigned to the same field of the bd and you stop with a brief script.
Here you can see how my options appear in my checkbox
:
Here you can see the interests saved:
There is no coincidence but in one and when I convert the explode
in imploder
this comes to me:
This is how I do the function in each checkbox
:
<tr>
<td><center><label >Edad: </label></center></td>
<td><input class="spinnerT" value="<?php echo $row["edad"]; ?>" id="edad" name="edad" TYPE="NUMBER" MIN="10" MAX="66" STEP="1" VALUE="20"></td
</tr>