Nathan Nathan - 3 months ago 13
HTML Question

tables and links messing the code up

I have a problem with PHP and links, I mean, I'm trying to use

<a href
to link the id of a ticket and then display it to user, but the problem is that the link I get is like

http://localhost/ucp/viewticket.php?ticketid=8%3Etest%3C/a%3E%3C/td%3E%3Ctd%3EUpute%20i%20informacije%3C/td%3E%3Ctd%3E2016-08-26%2000:06:59%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3E9%3C/td%3E%3Ctd%3ESale_Lesa%3C/td%3E%3Ctd%3E%3Ca%20href=

and it should only be like

http://localhost/ucp/viewticket.php?ticketid=8

This is the code:

if ($result = $con->query($query))
{
echo '
<table id="tfhover" class="tftable" border="1">
<th>ID Tiketa</th>
<th>Autor</th>
<th>Naslov</th>
<th>Kategorija</th>
<th>Datum</th>
';
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Autor'] . "</td>";
echo "<td><a href=\"viewticket.php?ticketid=". $row['ID'] .">". $row['Naslov'] ."</a></td>";
echo "<td>" . $row['Kategorija'] . "</td>";
echo "<td>" . $row['Datum'] . "</td>";
echo "</tr>";
}
$result->free();
}

Answer

When you change your Markup everything should be fine:

    while ($row = $result->fetch_assoc())
{
    echo '<tr>';
    echo '<td>' . $row['ID'] . '</td>';
    echo '<td>' . $row['Autor'] . '</td>';
    echo '<td><a href="viewticket.php?ticketid='. $row['ID'] .'">'. $row['Naslov'] .'</a></td>';
    echo '<td>' . $row['Kategorija'] . '</td>';
    echo '<td>' . $row['Datum'] . '</td>';
    echo '</tr>';
}

The Reason for this is, that there is a big difference between Single Quotes and Double Quotes.

Single Quotes are not parsed by PHP, so

$variable = 'hello';
echo '$variable' 

will still return: $variable

While

echo "$variable"

will parse the string to: Hello

This way you would have seen, that you missed an escaped double quote.

Comments