Then the only thing you need is to add the text of ESP in front of the code:
$codigo = (empty($consulta['num']) ? 1 : $consulta['num']+=1); echo 'El codigo actual es: '.$codigo;
$codigo='ESP'.$codigo; // te faltaria añadir esto.
$consulta = mysqli_query($mysql,'INSERT INTO num_ficha (num) VALUES ('.$codigo.')'); if(!$consulta){die('Error');}
However, I suggest that, when you are going to present the data (sure that at some point you do the SELECT query), at that moment add the 'ESP' in front.
This suggestion comes because most likely that code is from SPAIN, but when you have to internationalize it, it will be more convenient to relate the file with language / country, and then show the code according to that country. If this chip has to be changed and you have it inserted in the table, you would have to do truncate operations on that code.
In summary, you better do something kind:
$consulta = mysqli_query($mysql,'SELECT * FROM num_ficha');
if(!$consulta){die('Error');}
foreach($consulta as $fila) {
echo 'ESP'.$fila->get('num');
}