No setear datos cuando hay error
Publicado por informatic (13 intervenciones) el 03/06/2017 07:09:06
Hola, tengo un pequeño problema en este formulario, inserto bien las url y todo. pero cuando tengo un error me dice el error y tal pero me setea todos los parametros(url,titulo y texto). No se que hago mal, espero me ayuden
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require 'funciones.php';
$conexion = conexion('galeria','root','');
if (!$conexion) {
die();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$error = '';
$url= $_POST['url'];
$titulo = $_POST['titulo'];
$texto = $_POST['texto'];
if(!is_validUrl($url)){
$error .= 'La url no existe o no corresponde';
}else{
if(!empty($titulo)){
$titulo = filter_var($titulo,FILTER_SANITIZE_STRING);
}else{
$error .= 'Por favor ingresa un título <br />';
}
if(!empty($texto)){
$texto = filter_var($texto,FILTER_SANITIZE_STRING);
}else{
$error .= 'Por favor ingresa un título <br />';
}
if(!empty($url)){
$statement = $conexion->prepare('
INSERT INTO video (titulo,url,texto)
VALUES (:titulo, :url, :texto)
');
$statement->execute(array(
':titulo' => $titulo,
':url' => $url,
':texto' => $texto
));
if(!$error){
$error .= 'Has ingresado un nuevo video a tu galería';
}
}else{
$error .= 'Por favor ingresa una url<br />';
}
}
}
require 'views/subir.view.php';
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Slabo+27px" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/estilos.css">
<title>Galeria</title>
</head>
<body>
<header>
<div class="contenedor">
<h1 class="titulo">Subir Video</h1>
</div>
</header>
<div class="contenedor">
<form class="formulario" method="post" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<label for="foto">URL de vídeo</label>
<input type="text" id="video" name="video" placeholder="http://www.youtube.com/..." value="">
<label for="titulo">Titulo del vídeo</label>
<input type="text" id="titulo" name="titulo" placeholder="Título del vídeo">
<label for="texto">Descripción</label>
<textarea name="texto" id="texto" placeholder="Ingresa una descripcion"></textarea>
<?php if(isset($error)): ?>
<p class="error"><?php echo $error; ?></p>
<?php endif ?>
<input type="submit" class="submit" value="Subir Vídeo">
</form>
</div>
<footer>
<p class="copyright">Galeria creada </p>
</footer>
</body>
</html>
Valora esta pregunta


0