How can I improve this PHP MySQL rank query? In my db MySQL, I have a table ranks with many fields, one for each page I want limit access for the user in the menu application with PHP control:

  &lt;?php if ($row_ranks['padric'] == '1' ) {
    echo ('&lt;li&gt;&lt;a href="padroncini_ric.php"&gt;Ricerca&lt;/a&gt;&lt;/li&gt;');
        } 
        else  {
        echo ('&lt;li&gt;&lt;a href="#" class="disabled"&gt;Ricerca&lt;/a&gt;&lt;/li&gt;');
        } 
  ?&gt;


In the admin panel, I have a page for seting the privileges to single page with relative checkbox.

The checkbox as a name equal at field name in table like this example:

&lt;div&gt;
&lt;input type="checkbox" name="padric" value="1"
&lt;?php if ($row_user_ranks['padric'] == 1) { echo "checked"; } ?&gt;
&gt;Ricerca
&lt;/div&gt;


For set the privileges I make this PHP code:

    mysql_select_db($database_geomo, $geomo);
    $query_RSfields = sprintf("SHOW COLUMNS FROM ranks WHERE Field NOT IN ('ID', 'userID', 'gruppo')");
    $RSfields = mysql_query($query_RSfields, $geomo) or die(mysql_error());
    $row_RSfields = mysql_fetch_assoc($RSfields);
    $totalRows_RSfields = mysql_num_rows($RSfields);
    do { 
     $field = $row_RSfields['Field'] ;  

     if (!isset($_POST[$field])) { // set value = 0 for checkbox not checked
         $_POST[$field] = '0' ;
        }

    $updateSQL = sprintf("UPDATE ranks SET $field='".$_POST[$field]."' WHERE userID='".$_POST['ID']."'"); // set privileges for user
    mysql_select_db($database_geomo, $geomo);
    $Result1 = mysql_query($updateSQL, $geomo) or die(mysql_error());

    } while ($row_RSfields = mysql_fetch_assoc($RSfields));


I've made this code in this way because if the checkbox is not checked, it shouldn't return a value and should generate an error "unknown column" for the update SQL.

So, there is another more simply way for doing this job?
DO NOT USE THE mysql_* FUNCTIONS!
They are DEPRECATED.

&lt;?php if ($row_ranks['padric'] == '1' ) {
  echo ('&lt;li&gt;&lt;a href=&quot;padroncini_ric.php&quot;&gt;Ricerca&lt;/a&gt;&lt;/li&gt;');
      } 
      else  {
      echo ('&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;disabled&quot;&gt;Ricerca&lt;/a&gt;&lt;/li&gt;');
      } 
?&gt;

Your indentation style is a mess, decide what indentation style to use and if to use tabs or spaces (and if yes how many) and then stick to it:
&lt;?php
    if ($row_ranks['padric'] == '1' ) {
        echo '&lt;li&gt;&lt;a href=&quot;padroncini_ric.php&quot;&gt;Ricerca&lt;/a&gt;&lt;/li&gt;';
    } else  {
        echo '&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;disabled&quot;&gt;Ricerca&lt;/a&gt;&lt;/li&gt;';
    } 
?&gt;

Normally there's also no space between the line and the closing semicolon.
Additionally the echo function does not need any parentheses.

if ($row_ranks['padric'] == '1' )

If your code is in your native language, please always convert it to English before posting it here for review. It makes things easier for us.
Now what you use here is called a magic string or magic number, it's a fixed value that has some meaning but does not provide any explanation what's-o-ever what that meaning is or why it is that way. Use named constants instead.
const SOME_CONDITION = &quot;1&quot;; // Change the name to something meaningful.

if ($row['padric'] == SOME_CONDITION) {

Also do you now the difference between the equality and identity operator? The equality operator == will perform casting as needed which can yield interesting effects, the identity operator === on the other hand will also compare the types.
Some examples:
0 == 0     --&gt;  true
0 == &quot;0&quot;   --&gt;  true
0 == &quot;&quot;    --&gt;  true
0 == NULL  --&gt;  true

0 === 0     --&gt;  true
0 === &quot;0&quot;   --&gt;  false
0 === &quot;&quot;    --&gt;  false
0 === NULL  --&gt;  false

So always sue === unless you have a compelling reason not to.

$_POST[$field] = '0' ;

First of all, global variables are bad. And after that, writing into the Super-Globals is a bad idea for many reasons. Nobody expects that super globals are modified in any way and that can lead to funny errors which you'll be looking for for days.
Extract the values from the super globals and work with that variable.

$updateSQL = sprintf(&quot;UPDATE ranks SET $field='&quot;.$_POST[$field].&quot;' WHERE userID='&quot;.$_POST['ID'].&quot;'&quot;); // set privileges for user

One word (okay, it's two): SQL Injection. There is no, absolutely no (and I mean no) excuse to allow SQL injection. Imagine somebody would manipulate the POST request to contain the value '; DROP TABLE ranks; -- which will yield the query:
UPDATE ranks SET field='field' WHERE userID=''; DROP TABLE ranks; --'

...any questions?
Why are you using sprintf here?

$row_RSfields = mysql_fetch_assoc($RSfields);
do {
    // code 
} while ($row_RSfields = mysql_fetch_assoc($RSfields));

Traditionally it's a while loop:
$result = getResult();
while ($row = fetchRow($result)) {

}


Now let's get to the core problem: You are using the mysql_* functions. You should either use mysqli_* or PDO.
Personally I prefer PDO over mysqli_* because it has an object oriented interface and support multi-statements. So here's an example on how to use PDO:
/**
 * 
 * @var PDO
 */
$pdo = new PDO($dsn, $user, $password, $options);
$pdo-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // See footnote!

/**
 *
 * @var PDOStatement
 */
$statement = $pdo-&gt;prepare(&quot;SELECT field FROM table WHERE id = :id;&quot;);
$statement-&gt;bindValue(&quot;:id&quot;, $id, PDO::PARAM_INT);

$statement-&gt;execute();

while ($row = $statement-&gt;fetch()) {
    echo $row['field'];
}

$statement-&gt;closeCursor();

Question on Stack Overflow about when to turn off emulated prepares.

Are you aware of the difference between strings?
'A simple string'
&quot;A string with automatic $variable expansion&quot;