Trying to get a link to a link to go to the next page

I am trying to get data from a link from this code and get an error message as shown below, what could be the problem in line 3 of the code?

while ($row = mysql_fetch_assoc($result))
    {
        echo "<a href=\"edit_employee.php?$row['employee_id_passport']\">" . $row['first_name'] ." " . $row['surname'] . "</a>";

        echo "<br />";
    }

Error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Library/WebServer/Documents/practice/employee/view_employee.php on line 14 
+3
source share
3 answers

Delete single quotes:

echo "<a href=\"edit_employee.php?$row[employee_id_passport]\">" . $row['first_name'] ." " . $row['surname'] . "</a>";
+5
source

AFAIK, you have 2 ways to resolve your request:

echo "<a href=\"edit_employee.php?{$row['employee_id_passport']}\">" . $row['first_name'] ." " . $row['surname'] . "</a>";

or

echo "<a href=\"edit_employee.php?" . $row['employee_id_passport'] . "\">" . $row['first_name'] ." " . $row['surname'] . "</a>";

or using a single quote to avoid escaping a double quote

echo '<a href="edit_employee.php?' . $row['employee_id_passport'] . '">' . $row['first_name'] . ' ' . $row['surname'] . '</a>';

Use $row[employee_id_passport]will result in a notification in the error log, because it is employee_id_passportinterpreted as a constant.

See manual , first note.

+3
source

All Articles