sostituisci
$sql="SELECT * from $table1 where codice = $codicenew";
con
$sql="SELECT * from $table1 where codice = '".$codicenew."'";
anche in sql le stringhe devono essere racchiuse tra apici, quindi se non metti apici intorno a $codicenew questa query funzionerà solo nel caso in cui $codicenew abbia un valore numerico.
p.s:Stessa cosa anche per le altre query..