Hi All
I have creating a database table that will store configuration values so that php knows whether to show a field within a html form or not.

I know that the PHP code connects to the table within the database as there are now errors when the webpage is loaded.

Each field stores only one item of data. The first field called 'fieldname' stores the name of the field I want to set a value for. The second field called 'value' stores a boolean value that indicates if the html form field should be shown.

The variable $field collects the mysql query result. However $field always seems to be 0 and doesn't seem to read 'value'(set to 1) in the database.

Am I being dense?! lol

if(!$DBC)

{

    die("not connected" . mysql_error());

}

$DB = mysql_select_db("table",$DBC);

if(!$DB)

{

    die("error" . mysql_error());

}

$field = mysql_query("select value from Table where fieldname = 'fullname'");
if($field == 1)
{
echo("showing fullname field ");

echo("<td>Your full name<br/>");

}else
echo("Not showing fullname field ";
?>

As per the PHP documentation (you do have a copy don't you!):

Return Values
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

You need to use this resource id in a mysql_fetch_array or mysql_fetch_assoc to return an array of rows and fields (in your case just one row and one field). You can also use mysql_result to return just one field from a specified row in the result.

Thanks Chrishea

That works perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.