Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>baja_usuario</title>
- </head>
- <body>
- <?php
- function connect_to_db($host = "localhost", $username = "root", $password = "", $dbname = "juralfa") {
- $conexion = mysql_connect("localhost", "root", "")
- or die("Problemas en la conexion");
- mysql_select_db("juralfa", $conexion)
- or die("Problemas en la selección de la base de datos");
- return $conexion;
- }
- function generic_query($type, $column, $table, $id = NULL) {
- // This should be in a configuration file or an .php.inc
- $templates = array(
- 'select' => 'SELECT %1$s FROM %2$s WHERE %1$s = %3$s',
- 'delete' => 'DELETE FROM %2$s WHERE %1$s = %3$s'
- );
- return sprintf($templates[$type], $column, $table, $id);
- }
- /*
- * El array está en este formato:
- * 'código' => array(nombretabla, columnaPK)
- */
- $schema = array(
- 'propietario' => array('propietario', 'id_propietario'),
- 'apiario' => array('apiarios', 'id_apiario'),
- 'colmena' => array('colmena', 'id_colmena'),
- 'producto' => array('productos', 'id_producto'),
- 'registro' => array('registros_salud', 'id_registro')
- );
- public function baja($entidad, $id) {
- $conexion = connect_to_db();
- $tabla = $schema[$entidad][0];
- $columna = $schema[$entidad][1];
- $select_query = generic_query('select', $tabla, $columna, $id);
- $registros = mysql_query($select_query, $conexion)
- or die('Problemas en el select: ' . mysql_error());
- if($reg = mysql_fetch_array($registros)) {
- $delete_query = generic_query('delete', $tabla, $columna, $id);
- mysql_query($delete_query, $conexion)
- or die('Problemas en el delete: ' . mysql_error());
- echo "Se efectuo el borrado del propietario con dicho codigo";
- } else {
- echo "No existe un usuario con ese id.";
- }
- mysql_close($conexion);
- }
- baja($_GET['entidad'], $_GET['id']);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment