简体   繁体   中英

Use of undefined constant id - assumed

Hi i am getting this message on my index.php

Notice: Use of undefined constant id - assumed 'id' in C:\\xampp\\htdocs\\practice\\index.php on line 70

Notice: Use of undefined constant department - assumed 'department' in C:\\xampp\\htdocs\\practice\\index.php on line 71

Notice: Use of undefined constant custodian - assumed 'custodian' in C:\\xampp\\htdocs\\practice\\index.php on line 72

Notice: Use of undefined constant location - assumed 'location' in C:\\xampp\\htdocs\\practice\\index.php on line 73

Notice: Use of undefined constant brand - assumed 'brand' in C:\\xampp\\htdocs\\practice\\index.php on line 74

Notice: Use of undefined constant model - assumed 'model' in C:\\xampp\\htdocs\\practice\\index.php on line 75

Notice: Use of undefined constant hardwaresn - assumed 'hardwaresn' in C:\\xampp\\htdocs\\practice\\index.php on line 76

Notice: Use of undefined constant hardisk - assumed 'hardisk' in C:\\xampp\\htdocs\\practice\\index.php on line 77

Notice: Use of undefined constant processor - assumed 'processor' in C:\\xampp\\htdocs\\practice\\index.php on line 78

Notice: Use of undefined constant ram - assumed 'ram' in C:\\xampp\\htdocs\\practice\\index.php on line 79

Notice: Use of undefined constant monitor - assumed 'monitor' in C:\\xampp\\htdocs\\practice\\index.php on line 80

Notice: Use of undefined constant actualos - assumed 'actualos' in C:\\xampp\\htdocs\\practice\\index.php on line 81

Notice: Use of undefined constant msoffice - assumed 'msoffice' in C:\\xampp\\htdocs\\practice\\index.php on line 82

Notice: Use of undefined constant supplier - assumed 'supplier' in C:\\xampp\\htdocs\\practice\\index.php on line 83

Notice: Use of undefined constant invoicenumber - assumed 'invoicenumber' in C:\\xampp\\htdocs\\practice\\index.php on line 84

Notice: Use of undefined constant purchasedate - assumed 'purchasedate' in C:\\xampp\\htdocs\\practice\\index.php on line 85

Notice: Use of undefined constant warranty - assumed 'warranty' in C:\\xampp\\htdocs\\practice\\index.php on line 86

Id  Deparment   Custodian   Location    Brand   Model   Hardware SN Case/Monitor    HardDisk    Processor   Ram Monitor Actual OS   MS Office   Supplier    Invoice No. Purchase Date   Warranty    Line to Edit    Line to Delete
1   Motor   Ibrahim Abu Lebda   1st Floor   Lenovo  MTM 10A9-003CAX PC08KULS/ CNC137R2N1    1TB Intel Core i7   8GB 20'' LED HP Win 7 Pro   2013            0000-00-00  Out Of Warranty Edit    Delete
Add New Record

and here is my codes please help me to identify what is not declare.

  <html>
<head>
<title>IT Equipment Inventory System</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>

<h1><center>IT Equipment Inventory System</center></h1>

<?php



echo "<marquee>" . "Today is " . date("m/d/Y")  . "</marquee>";
echo "<marquee>" . "Today is " . date("l") . "</marquee>";


?>

<?php
// connect to the database
include 'db_connection.php';

$conn = OpenCon();

//echo "Connected Successfully";


// get the records from the database

$result = mysqli_query($conn, "SELECT * FROM tb1");
CloseCon($conn);



// display records in a table

echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
echo "<table border='1' cellpadding='10'>";

// set table headers
echo "<tr>
    <th>Id</th>
    <th>Deparment</th> 
    <th>Custodian</th> 
    <th>Location</th>
    <th>Brand</th>
    <th>Model</th>
    <th>Hardware SN Case/Monitor</th>
    <th>HardDisk</th>
    <th>Processor</th>
    <th>Ram</th>
    <th>Monitor</th>
    <th>Actual OS</th>
    <th>MS Office</th>
    <th>Supplier</th>
    <th>Invoice No.</th>
    <th>Purchase Date</th>
    <th>Warranty</th>
    <th>Line to Edit</th>
    <th>Line to Delete</th>
  </tr>";

while($row = mysqli_fetch_array( $result )) {


// set up a row for each record
echo '<tr>';
echo '<td>' . $row[id]            .   '</td>';
echo '<td>' . $row[department]    .   '</td>';
echo '<td>' . $row[custodian]     .   '</td>';
echo '<td>' . $row[location]      .   '</td>';
echo '<td>' . $row[brand]         .   '</td>';
echo '<td>' . $row[model]         .   '</td>';
echo '<td>' . $row[hardwaresn]    .   '</td>';
echo '<td>' . $row[hardisk]       .   '</td>';
echo '<td>' . $row[processor]     .   '</td>';
echo '<td>' . $row[ram]           .   '</td>';
echo '<td>' . $row[monitor]       .   '</td>';
echo '<td>' . $row[actualos]      .   '</td>';
echo '<td>' . $row[msoffice]      .   '</td>';
echo '<td>' . $row[supplier]      .   '</td>';
echo '<td>' . $row[invoicenumber] .   '</td>';
echo '<td>' . $row[purchasedate]  .   '</td>';
echo '<td>' . $row[warranty]      .   '</td>';


echo '<td><a href="edit.php?id='   . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo '</tr>';
}

echo "</table>";
?>

<a href="New.php">Add New Record</a>
</body>
</html>

You forgot to add quotes around index names inside while() code.

For example:- $row[id] need to be $row['id']

Do like below:-

while($row = mysqli_fetch_assoc( $result )) {

    // set up a row for each record
    echo '<tr>';
    echo '<td>' . $row['id']            .   '</td>';
    echo '<td>' . $row['department']    .   '</td>';
    echo '<td>' . $row['custodian']     .   '</td>';
    echo '<td>' . $row['location']      .   '</td>';
    echo '<td>' . $row['brand']         .   '</td>';
    echo '<td>' . $row['model']         .   '</td>';
    echo '<td>' . $row['hardwaresn']    .   '</td>';
    echo '<td>' . $row['hardisk']       .   '</td>';
    echo '<td>' . $row['processor']     .   '</td>';
    echo '<td>' . $row['ram']           .   '</td>';
    echo '<td>' . $row['monitor']       .   '</td>';
    echo '<td>' . $row['actualos']      .   '</td>';
    echo '<td>' . $row['msoffice']      .   '</td>';
    echo '<td>' . $row['supplier']      .   '</td>';
    echo '<td>' . $row['invoicenumber'] .   '</td>';
    echo '<td>' . $row['purchasedate']  .   '</td>';
    echo '<td>' . $row['warranty']      .   '</td>';


    echo '<td><a href="edit.php?id='   . $row['id'] . '">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo '</tr>';
}

Note:- use mysqli_fetch_assoc() instead of mysqli_fetch_array , so that associative array only will come.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM