I am new in these areas I found your page on the WEB and I want a little hand for this system that I am doing, since my expertise with programming and web development is really basic and I am still in the process of perfecting myself and learning more.
I'm going to the point, the problem I have is that through a registration form I have only textbox to add data. The thing is that they asked me to add a dynamic select and I forgot how to install it inside my maintainer. However create the fields and a table that is related to another to be able to make references and show the data that comes out there, the drama is not to show the select and make it look in a list. I will add the forms and the database.
Database
use master;
create database intranet;
use intranet;
create table cargo(
cod_cargo int (5) PRIMARY KEY,
nom_cargo varchar(30),
foreign key (cod_cargo) REFERENCES usuarios(cod_cargo)
);
insert into cargo values ('1','Secretaria Alcaldia');
insert into cargo values ('2','Jefe de Gabinete');
insert into cargo values ('3','Secretaria de Administracion');
insert into cargo values ('4','Encargado de Informatica');
insert into cargo values ('5','Oficina de Partes');
insert into cargo values ('6','Encargada de OIRS');
drop table cargo;
create table usuarios(
usuario varchar(45) PRIMARY KEY,
clave varchar(45) NOT NULL,
cod_cargo int (5) NOT NULL,
cargo varchar (45) NOT NULL,
admin boolean NOT NULL,
foreign key (cod_cargo) references cargo (cod_cargo)
);
insert into usuarios values
('Admin','123456','1','Administrador',1);
drop table usuarios;
Registration form with HTML code , here is where I enter the data, supposedly I have to add a SELECT below the key Textbox and replace the one that is there.
<?php
require '../scripts/funciones.php';
if(! haIniciadoSesion() || ! esAdmin() )
{
header('Location: index.html');
}
conectar();
$usuarios = getUsuario();
desconectar();
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Panel de Administración</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- Custom styles for this template -->
<link href="../css/dashboard.css" rel="stylesheet">
<!-- Validaciones en JavaScript -->
<script src="validar-usuario.js" type="text/javascript"></script>
<!-- CSS ME -->
<link rel="stylesheet" type="text/css" href="../css/estilos.css">
</head>
<body>
<?php include './menu-superior.php'; ?>
<div class="container-fluid">
<div class="row">
<?php include './sidebar.php'; ?>
<!-- <?php include './menu-lateral.php'; ?> -->
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" >
<h1 class="page-header">Agregar Nuevo Usuario:</h1>
<form action="registro.php" method="post" onsubmit="return validar();">
<div class="form-group">
<label for="email">Usuario:</label>
<input style="width: 20%;" type="text" class="form-control" id="txtUsuario" name="txtUsuario" placeholder="Ingrese Usuario" required="required" >
</div>
<div class="form-group">
<label for="pwd">Clave:</label>
<input style="width: 20%;" type="password" class="form-control" id="txtClave" name="txtClave" placeholder="Ingrese Clave"required="required" >
</div>
<label for="pwd">Cargo:</label>
<br>
<select style="width: 20%;" name="cargo" size="0">
<?php
while ($arreglo = mysql_fetch_array($query)) { ?>
<option value="<?php echo $arreglo ['cod_cargo']?>"><?php echo $arreglo['nom_cargo']?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="pwd">N° de Permiso (1 para admin y 0 para usuario):</label>
<br>
<input style="width: 20%;" type="number" class="form-control" id="txtAdmin" name="txtAdmin" placeholder="Ingrese N° de Permiso"required="required">
<hr>
<button type="submit" id="btnguardar" name="btnguardar" class="btn btn-primary">Guardar</button>
<input type="reset" name="btn-reset" value="Limpiar Campos" class="btn btn-primary">
</form>
</div>
<?php
if(isset($_POST['btnguardar'])){
require("registro.php");
}
?>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</body>
</html>
PHP Registry , page where I insert the data.
<?php
$conexion;
require '../scripts/funciones.php';
conectar();
// CREACION DE VARIABLES $USUARIO, $CLAVE, $CARGO Y $PERMISO PARA ALMACENAR LOS DATOS
$usuario = $_POST['txtUsuario'];
$clave = $_POST['txtClave'];
$cargo = $_POST['txtCargo'];
$permiso = $_POST['txtAdmin'];
// CONSULTA PARA INSERTAR LOS DATOS RECOGIDOS EN LAS VARIABLES DENTRO DEL FORMULARIO
$insertar = mysqli_query($conexion, "INSERT INTO usuarios VALUES('".$usuario."', '".$clave."', '".$cargo."', '".$permiso."')");
// EJECUCION DE CONSULTA
$resultado = mysqli_query($conexion, $insertar);
// IF PARA VERIFICAR SI EL USUARIO SE REGISTRO O NO, DE LO CONTRARIO INGRESE NUEVAMENTE LOS DATOS
if(!$resultado){
echo'<script>alert("Usuario registrado satisfactoriamente!")</script>';
echo'<script>alert("Ahora elija los permisos para el usuario.")</script>';
echo '<script>location.href ="permisos.php"</script>';
}else
{
echo '<script>alert("Error, Usuario no Registrado.")</script>';
}
mysqli_close($conexion);
?>
It would be very helpful if you can help me, I would greatly appreciate a lot of greetings to all from Chile.