You can not list using mysql_fetch_array without using a while or a for because mysql fetch array works with records one by one and not with an array of records that is necessary to work with foreach. If you need the foreach here, I show you an adaptation to your code:
$query = "SELECT id_prod FROM productos WHERE nombre_prod='$nombre' OR descrip='$caract' ";
$result = mysqli_query($con, $query);
$registros = array();
while ($mostrar = mysqli_fetch_array($result)) {
$registros[] = $mostrar;
}
foreach($registros as $mostrar){
$id_producto = $mostrar['id_prod'];
}