...

View Full Version : Select by username OOP Problem



Kev0121
03-28-2009, 06:08 PM
Well trying to select by a username heres my error


Database query error Unknown column 'Kevin' in 'where clause'

heres my selecta_u method


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
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'];


?>

steelaz
03-28-2009, 06:36 PM
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}'.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum