How to get a number from sql database

software development


Hi i was wonder how to receive a number from a the sql database i have a column named admin and i need it so that $admin equals what is written there(like 1). I was thinking of using the Select command kind of like

Select admin from $table where username = $username

but i dont know exactly every thing i have to do so it sets the $admin. I have tried many different thing but it always ends up that when i do an echo $admin it displays…

$admin = Select admin from $table where username = $username

If someone could help me that would be great!


Here is an entire script that I think does what you were asking.[code]<?php

$db_hostname = “hostname”;
$db_username = “username”;
$db_password = “password”;
$db_name = “database”;

$link = mysql_connect($db_hostname, $db_username, $db_password);
if (!$link) {
die('Could not connect: ’ . mysql_error());

if (!mysql_select_db($db_name, $link)) {
die('Could not use database: ’ . mysql_error($link));

header(“Content-Type: text/plain”);

$username = $_POST[‘username’];

echo "Username provided: " . htmlspecialchars($username) . “\n”;

$query =
“SELECT admin FROM users WHERE username=’%s’”,

$result = mysql_query($query, $link);
if (!$result) {
die('Query failure: ’ . mysql_error($link));

$row_count = mysql_num_rows($result);

if ($row_count > 1) {
die(‘Database error: multiple rows matched query’);
elseif ($row_count == 0) {
echo “User not found in database\n”;
else {
$user = mysql_fetch_assoc($result);
if ($user[‘admin’] == 1) {
echo “User is an admin\n”;
else {
echo “User is not an admin\n”;

?>[/code] :cool: -//-