Undefined index in php and SQLite3

3

I need help with an error, I am inserting data in a table called "posts" but it gives me the news that in certain fields where null is allowed, it says "Undefined index ... in ....... .... "

I do not understand why this error occurs if these fields supposedly accept NULL.

Thank you very much

This shows on the website that I'm doing as an exercise

Aqui van los post
Notice: Undefined index: imagen in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 11

Notice: Undefined index: anio in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 12

Notice: Undefined index: mes in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 12

Notice: Undefined index: dia in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 12

Notice: Undefined index: subtitulo in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 14

Notice: Undefined index: texto in C:\xampp\htdocs\CursoVideo2Brain\blogphp\includes\posts.php on line 15

Here is the code that generates the error:

<?php

$db = new SQLite3('database/blogs.db');

$resultado = $db->query("SELECT * FROM posts WHERE usuario='".$_SESSION['usuariotemporal']."' ORDER BY utc DESC LIMIT 3");

while($fila = $resultado->fetchArray())
{
    echo "
    <article>
    <div id='logov2b' style='background:url(\"photo/".$_SESSION['imagen'].".jpg\");'></div>
    <time>".$_SESSION['anio']."-".$_SESSION['mes']."-".$_SESSION['dia']."</time>
    <h3>".$_SESSION['titulo']."</h3>
    <h4>".$_SESSION['subtitulo']."</h4>
    <p>".$_SESSION['texto']."</p>
    <br/>";
    if($_SESSION['login'] == "yes")
    {
        echo "<a href='includes/eliminarpost.php?utc=".$fila['utc']."'>Eliminar</a><br/>";
    }

    if($_SESSION['login'] == "yes")
    {
        echo "<a href='index.php?titulomod=".$fila['titulo']."&subtitulomod=".$fila['subtitulo']."&textomod=".$fila['texto']."&editando=yes&utc=".$fila['utc']."'>Modificar</a><br/>";
    }

    echo "</article>";
}

$db->close();

?>
    
asked by Augusto Herbel 12.02.2016 в 04:51
source

2 answers

1

What I see is that you are not inserting anything in the database, you are generating a query Select so you are getting data from the database to display them. The errors do not have to do with the query have to do with the variables not defined imagen , anio , mes , etc. The recommendation is to declare these variables or use isset() Example:

 '$variable= isset($_POST['variable']) ? $_POST['variable'] : '';'  

or

if (isset($_POST['variable']) ){ 

        $variable=  $_POST['variable'];
}

0 in this case

if (isset($_SESSION['variable']) ){ 

        $variable=  $_SESSION['variable'];
}

Greetings

    
answered by 12.02.2016 / 05:53
source
1

The error gives you the answer. You are trying to print session variables that are not defined. You should change something like:

$_SESSION['anio']

for

$fila['anio']

I think that's where your problem is.

    
answered by 10.08.2016 в 14:44