Prostate cancer (PCa) and benign prostatic hyperplasia (BPH) are common male diseases whose incidence rates gradually increase with age. They seriously affect men's physical health and quality of life. This study aimed to identify new biomarkers for the diagnosis of BPH and PCa. Two datasets, GSE28204 and GSE134051 (including human PCa and BPH), were downloaded from the GEO database. The batch effect was removed for merging, and then differential gene expression analysis was conducted to identify BPH and PCa cases. The diagnostic biomarkers of BPH and PCa were further screened using machine learning and bioinformatics. ROC curves were drawn to evaluate the diagnostic accuracy of the selected biomarkers. An online website and qPCR were used to preliminarily explore the expression levels of PCa biomarkers. The correlations between the expression of biomarkers and the tumor microenvironment, tumor mutation load and immunotherapy drugs were evaluated. We identified fifteen genes (CHRDL1, DES, FLNC, GSTP1, MYL9, TGFB3, NEFH, TAGLN, SPARCL1, SYNM, TRPM8, HPN, PLA2G7, ENTPD5 and GPR160) as critical diagnostic biomarkers. After reviewing the literature on all selected biomarkers, we found few studies on the four genes CHRDL1, NEFH, TAGLN and SYNM in BPH or PCa. We defined these four genes as new potential diagnostic biomarkers (NPDBs) of BPH and PCa. All NPDBs were downregulated in PCa patients and PCa cell lines and upregulated in BPH patients and cell lines. When the immune landscape and mutation frequencies were analyzed, the results showed that the tumor microenvironment (TME), immune landscape, tumor mutation burden, and drug response were significantly correlated with NPDB expressions. We found four new diagnostic markers of BPH and PCa, which may facilitate the early diagnosis, treatment, and immunotherapeutic responses assessment and may be of major value in guiding clinical practice.