Web Analytics Made Easy -
StatCounter Little query problem - CodingForum

Announcement

Collapse
No announcement yet.

Little query problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Little query problem

    Hi,

    I have a little problem: i have a textbox and i want the name of the user who's logged in in that textbox (through the database). This is my code:

    Code:
    <tr>
       <td width="100"><span class="style4">Name:</span></td>
       <?
          $user = $_SESSION['username'];
          $query  = "SELECT name FROM users WHERE username=$user";
          $result = mysql_query($query);
          echo "<td width='250'><input name='name' type='text' size='34' value='$result'></td>";
       ?>
    </tr>
    I connected to the database but it doesn't show me anything so i think my query is wrong.

    Thank you

  • #2
    Try:
    PHP Code:
    <tr>
       <td width="100"><span class="style4">Name:</span></td>
       <?
          $user 
    $_SESSION['username'];
          
    $query  "SELECT name FROM users WHERE username='$user'";
          
    $result mysql_query($query);
          
    $name mysql_result($result0);
          echo 
    '<td width="250"><input name="name" type="text" size="34" value="' $name '"></td>';
       
    ?>
    </tr>
    -Brando
    Why using tables for eating is stupid!

    Comment


    • #3
      I'm no PHP guy, but I think you need single quotes around your username variable. That's how you specify a string instead of a number, at least in ASP \ SQL. That is assuming you have the user name field defined as a string.

      Edit: Yep.


      Basscyst
      Helping to build a bigger box. - Adam Matthews

      Comment


      • #4
        Thank you very much, it works now

        Comment

        Working...
        X