Unknown column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Unknown column

Post 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 :?
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you need quotes around string values in mysql :wink:
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post 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?
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Code: Select all

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