php - Undefined index, when using mysqli_fetch_assoc, SELECT * -
this question has answer here:
i have simple inventory db. when trying access products table , display data in table, continually "unidentified index" , nothing have found far can assist me. starting php
conn.php
<?php $servername = "localhost"; $username = "root"; $password = ""; $database = "slfs_storesb"; // create connection $conn = new mysqli($servername, $username, $password, $database); // check connection if ($conn->connect_errno) { printf("connection failed: %s\n" . $conn->connect_error); } ?>
index.php
<?php $sql = "select * tbl_station"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_assoc($result)) { var_dump($row); // print $row[4]; //echo '<table id="t01">'; echo $row["station_id"]." ".$row["station_name"]." ". $row["station_email"]; // echo '</table>'; } // } else { // echo "0 results"; // } ?>
this error
notice: undefined index: station_id in c:\wamp\www\stores\index_1.php on line 21 call stack # time memory function location 1 0.0010 246504 {main}( ) ..\index_1.php:0 gros islet fire station ( ! ) notice: undefined index: station_id in c:\wamp\www\stores\index_1.php on line 21 call stack # time memory function location 1 0.0010 246504 {main}( ) ..\index_1.php:0 gfl fire hall ( ! ) notice: undefined index: station_id in c:\wamp\www\stores\index_1.php on line 21 call stack # time memory function location 1 0.0010 246504 {main}( ) ..\index_1.php:0 headquarters ( ! ) notice: undefined index: station_id in c:\wamp\www\stores\index_1.php on line 21 call stack # time memory function location 1 0.0010 246504 {main}( ) ..\index_1.php:0 dennery class footer { footer }
instead of using select *
spell out (three) fields want access.
way query fail if 1 of fields misspelled (or doesn't exist in table).
<?php $sql = ' select station_id, station_name, station_email tbl_station '; $result = $conn->query($sql) or trigger_error('query failed: '.join(',', $conn->error_list)); while( $row=$result->fetch_assoc() ) { echo $row['station_id'], ' ', $row['station_name'],' ', $row["station_email"], "<br />\r\n"; }
Comments
Post a Comment