Unknown column

Discussion in 'PHP' started by promotingspace.net, Jul 3, 2007.

  1. #1
    Hi
    I want to show the user his articles using this code:

    <?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();
    ?>
    PHP:
    but the output is:
    I have checked the spelling and have not found a mistake. it's so strange :?
     
    promotingspace.net, Jul 3, 2007 IP
  2. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need quotes around strings in queries.

    $result = mysql_query("SELECT * FROM articles WHERE username='{$_SESSION['username']}' ORDER BY id") or die(mysql_error());
     
    KalvinB, Jul 3, 2007 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks
    now I want the article subjects clickable by something like:
    <a href=readarticle.php?id=$id> $row['subject']<a>
    PHP:
    at:
    <?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> مقالات شما </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();
    ?>
    
    PHP:
    How do I get that done? because you see somewhere I need something but where and what?
     
    promotingspace.net, Jul 3, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    
    <?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> مقالات شما </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();
    ?>
    
    PHP:
    and also, i would recommend reading this: http://parseerror.com/~pizza/select*isevil.html
     
    ansi, Jul 3, 2007 IP