SQL injection attacks pose a significant risk to the security of computer networks. These attacks have the potential to gain unauthorized access to sensitive data, modify or remove data, or even render entire websites and databases inoperable. Conventional techniques for identifying and stopping SQL injection attacks are frequently resource-intensive, rendering them unfeasible for devices that manage substantial amounts of traffic. The objective of the proposed research is to improve the identification and prevention of structured query language injection attacks (SQLIAs) in web applications, with a specific focus on attaining a high rate of detection while minimizing false alarms. We utilized flow data obtained from several SQL injection attack scenarios that specifically targeted widely-used database engines. We obtained a high level of accuracy in identifying and mitigating these assaults by utilizing machine learning methods, specifically logistic regression. The method we used showed a detection rate over 98% and a false alarm rate below 0.029%. The results demonstrate substantial enhancements in the prevention of unauthorized access and the protection of sensitive information within databases. The results of our research align with or surpass current techniques, offering enhanced security for web applications. The model’s exceptional accuracy and minimal false alarm rate provide a groundbreaking method for detecting SQL injection attacks.