Page 1 of 1

Unknown column

Posted: Tue Jul 03, 2007 2:37 pm
by m2babaey
Hi
I want to show the user his articles using this code:

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
$result = mysql_query("SELECT * FROM articles WHERE username={$_SESSION['username']} ORDER BY id") or die(mysql_error());?> <p align=center> your articles</p>  <?
while($row = mysql_fetch_array( $result )) {
echo $row['subject'] ."<br>".$row['title']."<br>".$row['text']."<br><br>";
}
mysql_close();
?>
but the output is:
Unknown column 'm2babaey' in 'where clause'
I have checked the spelling and have not found a mistake. it's so strange :?

Posted: Tue Jul 03, 2007 2:43 pm
by TheMoose
This portion: username={$_SESSION['username']}

has no single quotes, so it's comparing the 'username' column against the 'm2babaey' column, which as you could tell, does not exist. If you want to check against the value, enclose it in quotes so it reads it as the string value.

Posted: Tue Jul 03, 2007 2:43 pm
by John Cartwright
you need quotes around string values in mysql :wink:

Posted: Tue Jul 03, 2007 3:07 pm
by m2babaey
thanks
now I want the article subjects clickable by something like:

Code: Select all

<a href=readarticle.php?id=$id> $row['subject']<a>
at:

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
$result = mysql_query("SELECT * FROM articles WHERE username='{$_SESSION['username']}' ORDER BY id") or die(mysql_error());?> <p align=center> &#1605;&#1602;&#1575;&#1604;&#1575;&#1578; &#1588;&#1605;&#1575; </p>  <?
while($row = mysql_fetch_array( $result )) {
echo <a href=readarticle.php?id=$id> $row['subject']<a> ."<br>".$row['title']."<br>".$row['text']."<br><br>";
}
mysql_close();
?>
How do I get that done? because you see somewhere I need something but where and what?

Posted: Tue Jul 03, 2007 3:15 pm
by spamyboy

Code: Select all

echo "<a href=\"readarticle.php?id=$id\">$row['subject']</a><br />$row['title']<br />$row['text']<br />";