jose.rebolledo
jose.rebolledo

Reputation: 13

echo on html just prints one word of a sentence

We are getting the values from the select and then trying to print them on a textbox so we can edit it. But when test it, the echo on the value just returns the first word of the sentence that is inside the column. For example our row[2] is the column "Nombre" with the value "estadio nacional", when we print it, the echo only return "estadio".

<!DOCTYPE html> 
<html> 
<head> 
    <title>Editar Estadio</title> 
</head> 

<body> 
    <h1>Editar Estadios</h1> 
    <?php
// Conectando y seleccionado la base de datos  
$dbconn = pg_connect("host=localhost dbname=tarea3 user=postgres password=12345")
    or die('No se ha podido conectar: ' . pg_last_error());
$id_1 = $_GET["id"];
$result=pg_query("SELECT * FROM estadio where id_estadio='".$id_1."'");
$row=pg_fetch_row($result, 0, PGSQL_NUM);
echo $row[2];
$nombre = $row[2];
?>
        <form method ='post' action='checkaddestadio.php'> 
            <pre> 
                Nombre: <input type='text' name='Nombre'  value=<?php echo $nombre ?>>
                Capacidad: <input type='text' name='Capacidad' value=<?php echo $row[3] ?>>
                Ciudad: <input type='text' name='Ciudad' value=<?php echo $row[4] ?>>
                Direccion: <input type='text' name='Direccion' value=<?php echo $row[5] ?>>
                Descripcion: <input type='text' name='Descripcion' value=<?php echo $row[6] ?>>
                Fotografia: <input type='text' name='Fotografia' value=<?php echo $row[1] ?>>                  
            </pre> 
            <br><input type='submit' value='Ingresar'></br> 
        </form>
<?php
// Cerrando la conexión
pg_close($dbconn);
?> 
</body> 
</html>

Upvotes: 1

Views: 1020

Answers (1)

Phil
Phil

Reputation: 164910

You need to use quotes around your HTML element attributes. As it stand, the HTML generated from your code would look like this

<input type='text' name='Nombre' value=estadio nacional>

See the problem?

You should also use htmlspecialchars() to avoid any XSS vulnerabilities or general HTML incorrect-ness, eg

<input type="text" name="Nombre" value="<?= htmlspecialchars($nombre) ?>">

Also, why the <pre> tags?

Upvotes: 2

Related Questions