am getting this error after executing the select query.


Notice: Undefined index: unit8_code in C:\wamp\www\ELIZA\viewresults.php on line 129

the following is line 129

$unit8_code=$row;


please help to troubleshoot

Dani AI

Generated

Short note: this was resolved when the database column name was corrected — thanks to for spotting that and to for confirming the fix.

Quick checklist for anyone who hits a similar "undefined index" when reading query results:

  • Make sure the SELECT actually returns the column and that spelling/aliases match what the code expects. Use MySQL DESCRIBE / SHOW COLUMNS to inspect table structure (see SHOW COLUMNS / DESCRIBE).
  • Confirm the fetch method returns associative keys. With mysqli use the associative fetch so column names become array keys (see mysqli_fetch_assoc).
  • Always check the query result before accessing fields. If the query failed or returned no rows, accessing keys will not work.
  • Guard against missing keys to avoid Notices. Example pattern:
if (isset($row['unit8_code'])) {
    $value = $row['unit8_code'];
} else {
    $value = null; // handle missing value
}
  • For long-term stability and security, use mysqli or PDO with prepared statements instead of the old mysql extension.

Enabling full error reporting on development systems helps catch typos quickly.

Recommended Answers

All 2 Replies

$row;
May be there is no column name as 'unit8_code' in your table;

thank you very much the problem was on the database the column name was refernced wrongly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.