Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Select by username OOP Problem

    Well trying to select by a username heres my error

    Database query error Unknown column 'Kevin' in 'where clause'
    heres my selecta_u method
    PHP Code:
    public function selecta_u($user) {
            global 
    $database;
            
    $result $database->query("SELECT * FROM test WHERE name = {$user}");
            
    $row $database->fear($result);
            return 
    $row;
        } 
    heres my query

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    require_once(
    'database.php');
    require_once(
    'user.php');

    $uname 'Kevin';

    $User = new User();
    $row $User->selecta_u($uname);

    echo 
    $row['city'];


    ?>

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    PHP Code:
    public function selecta_u($user) {
            global 
    $database;
            
    $result $database->query("SELECT * FROM test WHERE name = '{$user}'");
            
    $row $database->fear($result);
            return 
    $row;
        } 
    In your query, if value is a string, you have to encapsulate it in single quotes: '{$user}'.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •