Question

I'm experiencing this odd, yet annoying syntax problem for browsers. By coding the way below, I lose all the strings after the special character: "

    echo '<td><input type=text style=width:100px name=itembrand value="' . $itembrand . ' " </td>';
    echo '<td><input type=text style=width:150px name=itemname value="' . $itemname . '" </td>';
    echo '<td><input type=text style=width:150 name=serialnr value="' . $serialnr . '" </td>';
    echo '<td><input type=text style=width:150px name=addinfo value="' . $addinfo . '" </td><td>';

If I code the other way around, I lose everything after the ':

    echo "<td><input type=text style=width:37px name=code value='" . $code ."' </td>";
    echo "<td><input type=text style=width:100px name=itembrand value='" . $itembrand . "' </td>";
    echo "<td><input type=text style=width:150px name=itemname value='" . $itemname . "' </td>";
    echo "<td><input type=text style=width:150 name=serialnr value='" . $serialnr . "' </td>";
    echo "<td><input type=text style=width:150px name=addinfo value='" . $addinfo . "' </td><td>";

What is the correct syntax, to echo out database items even with ' and " together with the strings after it?

Note:
I'm using <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and the database entry is right, so this must be something with the syntax.

Was it helpful?

Solution

Ok, I used htmlspecialchars() to get this right. The code will be like:

    echo '<td><input type=text style=width:100px name=itembrand value="' . htmlspecialchars($itembrand) . ' " </td>';
    echo '<td><input type=text style=width:150px name=itemname value="' . htmlspecialchars($itemname) . '" </td>';
    echo '<td><input type=text style=width:150 name=serialnr value="' . htmlspecialchars($serialnr) . '" </td>';
    echo '<td><input type=text style=width:150px name=addinfo value="' . htmlspecialchars($addinfo) . '" </td><td>';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top