Home > Software engineering >  PHP: Unexpected 'StringLiteral'. Expected ','
PHP: Unexpected 'StringLiteral'. Expected ','

Time:11-26

I get this error notice in the VS code Unexpected 'StringLiteral'. Expected ',' with the PHP code below. Please help me understand what is wrong in it. I see this error with the line beginning with Click to..

while ($dbh->next_record()) {
    $tracker_info = json_decode($dbh->Record['tracker_info'], TRUE);
    inform_sl_operations("PO$dbh->Record['po_number'] needs Follow Up. Due: $dbh->Record['alert'] \n" 
        . " Click to <a href="'search_results.php?po_number=$dbh->Record['po_number']'">view order</a>,"
        . " [email protected]", "PO $dbh->Record['po_number'] needs Follow Up");
}

CodePudding user response:

Using " inside quotes, like:

$string = "href="example.com"";

Is wrong and needs to be escaped, like:

$string = "href=\"example.com\"";

Another possible mistake, don't do:

$string = "$dbh->Record['po_number']";

Store in variable then use, like:

$po_number = $dbh->Record['po_number'];
$string = " ... $po_number ... ";

Try something like:

while ($dbh->next_record()) {
    $tracker_info = json_decode($dbh->Record['tracker_info'], TRUE);

    $num = $dbh->Record['po_number'];
    $alert = $dbh->Record['alert'];

    inform_sl_operations("PO $num needs Follow Up. Due: $alert \n" 
        . " Click to <a href=\"search_results.php?po_number=$num\">view order</a>,"
        . " [email protected]", "PO $num needs Follow Up");
}

CodePudding user response:

You need to escape the double quotes in the href attribute of the <a>

"<a href=\".......\">"
  • Related