Forum Moderators: coopster

Message Too Old, No Replies

URL Variables giving Errors

Passing Variables as urls

         

mvaz

8:00 pm on Feb 5, 2010 (gmt 0)

10+ Year Member



Hello all, Could someone look into this code and advise me where I am going wrong. I have had sleepless nights trying to resolve this, but had absolutely no joy whatsoever.

----Code------
while ($row = mysql_fetch_array($result)) {
echo date('d F Y', strtotime($row['articleDate']));
echo stripslashes($row['articleTitle'];
echo "<a href=../display_article.php?id=.$row['id']>".$row['articleSubmittedBy'];
---EOC---

Basically what I am trying to do is extract data from mysql and list them on display_article.php with one of the data result is a link (href) for the article itself.

You guys have been very helpful in the past, and hope this time too, you will guide me in the right direction.

Many thanks in advance - Melwyn

rocknbil

11:27 pm on Feb 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missing closing function parenthesis.

echo stripslashes($row['articleTitle']);

You also have two missing quotes here, and no closing </a> (second is unrelated, but an HTML error.) "Spacing out" your concatenation dots tends to make these more identifiable:

echo "<a href=../display_article.php?id=" . $row['id'] . ">" . $row['articleSubmittedBy'] . "</a>";

Because I'm so retentive about valid output, you might consider quoting your attributes as well:


echo "<a href=\"/display_article.php?id=\"" . $row['id'] . "\">" . $row['articleSubmittedBy'] . "</a>";

Last, note I changed ../ to /, which means "start at the domain root" instead of doing something relative to "where you are." One day you'll find yourself doing this

../../../blah.php

when if you always use /, you can move the file anywhere in your system and it will link up with whatever resource you need. Aa perfect example is your CSS sheets or external JS.