-2

I want to populate the datas in a table form using php. im getting the output but its shows

Use of undefined constant classid - assumed 'classid'

And is it possible for me to add columns and store these values in new table?

Here is my code:

<html>
 <head>
   <title>grade1</title>
 </head>
 <body>
   <table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
     <tr>
       <th>classid</th>
       <th>studentid</th>
       <th>teacherid</th>
       <th>locid</th>
       <th>date</th>
       <th>flag</th>
       <th>comments</th>
     </tr>
     <?php
        $host = "localhost";
        $user = "root";
        $pass = "";
        $dbname = "my_attendance";
        $prefix = "";
        $dbcon = mysql_connect($host, $user, $pass) or die("not connected");

        mysql_select_db($dbname, $dbcon) or die("not selected");
        $query = "(SELECT  a.classid, a.fname, b.teacherid, c.locid
                   FROM class_master c JOIN student_master a 
                   ON c.classid = a.classid JOIN teacher_link b
                   ON c.classid = b.classid 
                   WHERE c.classid = 'grade1' )";
        $result = mysql_query($query);

        while( $row = mysql_fetch_array($result))
        {
          echo "<form action=insertattend.php method=POST>";
          echo "<tr>";
          echo "<td>" . "<input type=text value=" .$row[classid]." </td>";
          echo "<td>" . "<input type=text value=" .$row[fname]." </td>";
          echo "<td>" . "<input type=text value=" .$row[teacherid]." </td>";
          echo "<td>" . "<input type=text value=" .$row[locid]." </td>";
          mysql_close($dbcon);
        }
     ?>
</html>
Soma
  • 861
  • 2
  • 17
  • 32
user3145732
  • 29
  • 1
  • 7
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Jim Jan 03 '14 at 11:40

3 Answers3

1

Your missing quotes around array keys.

$row['classid']
$row['fname']
$row['teacherid']
$row['locid']

You have other issues here.

echo "<td>" . "<input type=text value=" .$row['classid']." </td>";

You are missing quotes around html attribute value and missing closing tag for <input>. Correct form will be

echo "<td>" . "<input type=\"text\" value=\"" .$row['classid']."\"></td>";

In these situations using single quotes saves from escaping the double quotes.

echo '<td>' . '<input type="text" value="' . $row['classid']. '>"</td>';

Also you should not use mysql_* functions.

Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
chanchal118
  • 3,551
  • 2
  • 26
  • 52
0

you need use single quote for array index, like:

echo "<td><input type=text value=" .$row['classid']." /> </td>";
rray
  • 2,518
  • 1
  • 28
  • 38
0

Several issues here. You need to encapsulate the keys, that's what's causing the error that you're reporting

$row['classid']

(You need to treat all those keys like that, not just classid.)

Close the input tag

" /></td>";

Wrap the HTML attribute values with quotes

type=\"text\" value=\"" .$row[classid]."\"

Quotes need escaping in the echo because the string is encapsulated with quotes.

 echo "<td><input type=\"text\" value=\"" .$row['classid']."\" /></td>";

You could use single quotes and not have to escape them

 echo '<td><input type="text" value="' .$row['classid'].'" /></td>';
Popnoodles
  • 28,090
  • 2
  • 45
  • 53