PHP BUTTON

I would need help on this problem:
I would like to create a PHP button that updates the value of a field in a table.
Example: Patient Table - Test Field (the test content is currently YES) I would like to change the content in all the records with the NO value.

I wrote the following PHP code inside the PHP button, but I get an error message:
------------------------------------------------------------ <?php

// I prepare the update query
$query = “UPDATE pazienti SET test = ‘NO’”;

// sending the query
$result = mysql_query($query);

// check the result
if (!$result) {
die("Errore in Azzeramento $query: " . mysql_error());
}

echo ‘Azzeramento eseguito correttamente’;
?>

If I execute the sql command in phpmyadmin (UPDATE patients SET test = ‘NO’) it works. I can not understand where I’m wrong, thanks for your help

I would probably create an Ajax event and place that code inside the event. Where is the button placed on the form OR toolbar ?

the button is placed in the toolbar

Try use macros for that. sc_exec_sql();

SOLVED!!!
/**

  • Update a record on another table
    */

// SQL statement parameters
$update_table = ‘cartellapaziente’; // Nome Tabella
$update_where = “Accettazione = ‘SI’”; // clausola Where
$update_fields = array( // Elenco dei campi, aggiungi il numero necessario
“Accettazione = ‘NO’”,
);

// Update record
$update_sql = ‘UPDATE ’ . $update_table
. ’ SET ’ . implode(’, ', $update_fields)
. ’ WHERE ’ . $update_where;
sc_exec_sql($update_sql);