I'm kinda new to php and since I started using it I encounter this error Notice: Undefined index: title_1
I connected the table
$ind_header = $db->query("SELECT * FROM header_index")->fetchAll(PDO::FETCH_ASSOC);
I try <?php echo $ind_header['title_1']; ?> I get that error, but when I use a foreach loop it works.
Now I wanna show the results of the database in a form value like this
<form action="<?php echo BASE_URL ?>/admin/admin.php" method="POST">
<label>Title one</label>
<input type="text" class="form-control" name="title_1" placeholder="Full name" value="<?php echo $ind_header['title_1']; ?>">
I get this full error
Notice: Undefined index: title_1 in D:\wamp\www\translate\app\views\cms\body_views\header.php on line 11 Call Stack #TimeMemoryFunctionLocation 10.0010132416{main}( )..\admin.php:0 20.0060141696require( 'D:\wamp\www\translate\app\views\admin\admin.php' )..\admin.php:4 30.0070145864include( 'D:\wamp\www\translate\app\views\cms\body.php' )..\admin.php:3 40.0070149056include( 'D:\wamp\www\translate\app\views\cms\body_views\header.php' )..\body.php:7 ">
->fetchAll()returns all rows in a multidimentional array, so that is why a foreach loop allows you to accesstitle_1. If you only want the 1st value, either change the->fetchAll()to->fetch()OR you can do$ind_header[0]['title_1']where[0]represents the row you want thetitle_1value from - Sean