I need help with an error, I am inserting data into a table called "posts" but it gives me the news that in certain fields where null is allowed it says "Undefined index ... in .......... ."
I don't understand why this error occurs if these fields are supposed to accept NULL.
Thank you very much
This shows on the web page that I am 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();
?>
What I see is that you are not inserting anything into the database, you are generating a query
Select
so you are getting data from the database to display. The errors have nothing to do with the query, they have to do with undefined variablesimagen
,anio
,mes
, etc. The recommendation is that you declare those variables or useisset()
Example:either
0 in this case
Cheers
The error gives you the answer. You are trying to print session variables that are not defined. You should change something like:
by
I think that's where your problem lies.