Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/01/2015, 09:01
festrada72
 
Fecha de Ingreso: enero-2015
Mensajes: 4
Antigüedad: 9 años, 3 meses
Puntos: 0
Respuesta: problemas con funciones

Perdonad la falta de información, lo he resumido para que se viera mas claro.
No lo he puesto en ninguna clase, no me atrevo todavía, si tengo problemas una simple función.

Al ejecutarlo no me da ningún error, me carga parte de la pagina y no me actualiza la tabla.
Ahi va todo el codigo.






<div id="wrapper" class="layout-1-column">
<?php

include_once 'menu.php';
include_once 'util/funciones.php';

function updatetrabajador($datos){

$sqlU = "UPDATE trabajadores set Tlfno_Oficial = ".$datos[4]." WHERE id_trabajador=" .$datos[0];

try {

$rec = $con->query($sqlU);
return true;
}
catch(PDOException $e)
{
echo $sqlU . "<br>" . $e->getMessage();
return false;
}


}


//Este array guardará los errores de validación que surjan.
$errores = array();
//Pregunta si está llegando una petición por POST, lo que significa que el usuario envió el formulario.

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : null;
$edad = isset($_POST['edad']) ? $_POST['edad'] : null;
$email = isset($_POST['email']) ? $_POST['email'] : null;

//campos requeridos

$DNI = GetSQLValueString( $_POST['DNI'], 'text');
$Apellidos = GetSQLValueString( $_POST['Apellidos'], 'text');
$Nombre = GetSQLValueString( $_POST['Nombre'], 'text');
$Tlfno1 = GetSQLValueString( $_POST['Tlfno1'], 'text');



//Valida que el campo nombre no esté vacío.

if (!validaRequerido($DNI)) {
$errores[] = 'El campo DNI es requerido.';
}if (!validaRequerido($Apellidos)) {
$errores[] = 'El campo Apellidos es requerido.';
}
if (!validaRequerido($Nombre)) {
$errores[] = 'El campo Nombre es requerido.';
}if (!validaRequerido($Tlfno1)) {
$errores[] = 'El campo Telefono1 es requerido.';
}

//Verifica si ha encontrado errores y de no haber redirige a la página con el mensaje de que pasó la validación.
if(!$errores){
$datos = array($_POST['id_trabajador'], GetSQLValueString( $_POST['DNI'], 'text'), GetSQLValueString( $_POST['Apellidos'], 'text'),
GetSQLValueString( $_POST['Nombre'], 'text'), GetSQLValueString( $_POST['Tlfno_Oficial'], 'int'), GetSQLValueString( $_POST['Tlfno1'], 'int'),
GetSQLValueString( $_POST['Tlfno2'], 'int'), GetSQLValueString( $_POST['email'], 'text'),
GetSQLValueString( $_POST['Fecha_Nacimiento'], 'date'), GetSQLValueString( $_POST['Fecha_Jubilacion'], 'date'), GetSQLValueString( $_POST['Direccion'], 'text'),
GetSQLValueString( $_POST['Localidad'], 'text'), GetSQLValueString( $_POST['CP'], 'text'), GetSQLValueString( $_POST['Informacion'], 'text') );


updatetrabajador($datos); // funcion que no funciona
// $sqlU = "UPDATE trabajadores set Tlfno_Oficial = ".$datos[4]." WHERE id_trabajador=" .$datos[0];

}
}
else
{

if (isset($_GET['id'])) {

$sqlP = "SELECT * FROM trabajadores where id_trabajador=".$_GET['id'];
$recP = $con->query($sqlP);
$rec = mysqli_fetch_object($recP);
//echo $sqlP;
}
}
?>
<div id="contenedor" >

<div id="main">
<?php if ($errores): ?>
<ul style="color: #f00;">
<?php foreach ($errores as $error): ?>
<li> <?php echo $error ?> </li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form id="editaT" action="editatrabajador.php" method="post" name="editaT">
<table>
<tbody>
<tr>
<td><strong>Id trabajador:</strong></td><td><input type="hidden" name="id_trabajador" value="<?php echo $rec->id_trabajador; ?>"><?php echo $rec->id_trabajador; ?></td>
<td></td>
<td><strong>DNI:</strong></td><td><input type="text" class="textbox" name="DNI" value="<?php echo $rec->DNI; ?>"> </td>
<td></td>
</tr>
<tr>
<td><strong>Apellidos:</strong></td><td colspan="2"><input type="text" class="textbox" name="Apellidos" size="50" value="<?php echo $rec->Apellidos;?>"> </td>
<td><strong>Nombre:</strong></td><td><input type="text" size="40" name="Nombre" class="textbox" value="<?php echo $rec->Nombre; ?>"> </td>

</tr>
<tr>
<td><strong>Tlfno Oficial:</strong></td><td><input type="text" class="textbox" name="Tlfno_Oficial" value="<?php echo $rec->Tlfno_Oficial; ?>"> </td>
<td><strong>Tlfno 1:</strong></td><td><input type="text" class="textbox" name="Tlfno1" value="<?php echo $rec->Tlfno1; ?>"> </td>
</tr>
<tr>
<td><strong>Tlfno 2:</strong></td><td><input type="text" name="Tlfno2" class="textbox" value="<?php echo $rec->Tlfno2; ?>"> </td>
<td><strong>Correo Elec:</strong></td><td colspan="2" ><input type="email" class="textbox" name="Correo_Elec" size="50" value="<?php echo $rec->Correo_Elec; ?>"> </td>
</tr>
<tr>
<td><strong>Fecha de Nacimiento:</strong></td><td><input type="text" name="Fecha_Nacimiento" class="textbox" value="<?php echo $rec->Fecha_Nacimiento; ?>"> </td>

<td><strong>Fecha de Jubilaci&oacute;n:</strong></td><td><input type="date" name="Fecha_Jubilacion" class="textbox" value="<?php echo $rec->Fecha_Jubilacion; ?>"> </td>
</tr>
<tr>
<td><strong>Direcci&oacute;n:</strong></td><td colspan="2"><input type="text" name="Direccion" class="textbox" size="50" value="<?php echo $rec->Direccion; ?>"> </td>
</tr>
<tr>
<td><strong>Localidad:</strong></td><td colspan="2"><input type="text" name="Localidad" class="textbox" size="50" value="<?php echo $rec->Localidad; ?>"> </td>
<td><strong>CP:</strong></td><td><input type="text" class="textbox" name="CP" value="<?php echo $rec->CP; ?>"> </td>
<td></td>

</tr>
<tr>
<td>
<strong>Informaci&oacute;n:</strong></td><td colspan="4">
<textarea placeholder="Informacion" name="Informacion" cols="50" class="textbox" rows="6" maxlength="200"><?php echo $rec->Informacion; ?></textarea>
</td>
</td>
</tr>
<tr>
<td>
<input type="submit" name="boton" class="boton" value="Guardar">
</td>
<td>
<input type="submit" name="boton" class="boton" value="Cancelar" onClick="location.href='plantilla.php'"
</td>
<td>
<input type="submit" name="boton" class="boton" value="Puestos">
<input name="MM_guarda" type="hidden" value="guarda" />
</td>


</tr>
</tbody>
</table>

</form>




</div><!-- id="main" --><!--Header.jsp-->


</div><!-- id="container" -->


<?php

include_once 'footer.php';
?>





</div><!-- id="wrapper" -->


</body>