Help getting values from MySQL database
Posted: Fri Jan 14, 2011 2:31 pm
Hello, I need help, as i'm trying to get a value from my user database which is the user ID (Auto Increment), when the user name is a specific value. For example when the user name is "UserTwo" the database gets the ID associated from that row which would be Two as it's the second user. However due to my lack of PHP knowlage I cannot understand why the $ID variable is blank.
Any help would really be appreciated.
Code: Select all
<?PHP
// Connects to your Database
include("db.php");
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
$query = ("SELECT ID FROM `users` WHERE username ='userone' ORDER BY `ID` ASC LIMIT 0 , 30");
$result = mysql_query($query);
$ID = "$result['ID']";
echo("$ID");
?>