PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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");
?>
<?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);
while($row = mysql_fetch_array($result)) {
$ID = $row['ID'];
echo $ID;
?>
That will pull all the information from that entire row and save $ID as the ID field, then on your echo I woulnd't use echo ('$ID');
just use echo $ID and you should be good to go.