I am trying to get a value of an int from a field in a MySql database and increment it by 1 when a new record is added. What is happening, is that when the record is inserted it is placing a 1 and not adding one to the value of the field. For example, in the last record, the value is 10 so after running the query the value should be 11.
I am struggling to see why this is not working and would be grateful if someone could offer any advice as to how to amend my code to a working solution. Many thanks
php code
function get_ref(){
$query = "SELECT MAX(`id_usr`) AS `max` FROM `user_usr`";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$max = $row['max'];
$sql = 'select idcom_usr'
. ' from user_usr'
. " where id_usr = '$max'"
. ' order '
. ' by id desc'
. " limit 1";
$result = mysql_query($sql);
$ref = mysql_result($result,0,"idcom_usr");
return $ref + 1;
}