The online detection of fertilizer information is pivotal for precise and intelligent variable-rate fertilizer application. However, traditional methods face challenges such as the complex quantification of multiple components and sensor-induced cross-contamination. This study investigates integrating near-infrared principles with machine learning algorithms to identify fertilizer types and concentrations. We utilized near-infrared transmission spectroscopy and applied Partial Least Squares Discriminant Analysis (PLS-DA), Support Vector Machine (SVM), and Back-Propagation Neural Network (BPNN) algorithms to analyze full spectrum data. The BPNN model, using S-G smoothing, demonstrated a superior classification performance for the nutrient ions of four fertilizer solutions: HPO42−, NH4+, H2PO4− and K+. Optimization using the competitive adaptive reweighted sampling (CARS) method yielded BPNN model RMSE values of 0.3201, 0.7160, 0.2036, and 0.0177 for HPO42−, NH4+, H2PO4−, and K+, respectively. Building on this foundation, we designed a four-channel fertilizer detection device based on the Lambert–Beer law, enabling the real-time detection of fertilizer types and concentrations. The test results confirmed the device’s robust stability, achieving 93% accuracy in identifying fertilizer types and concentrations, with RMSE values ranging from 1.0034 to 2.4947, all within ±8.0% error margin. This study addresses the practical requirements for online fertilizer detection in agricultural engineering, laying the groundwork for efficient water–fertilizer integration technology aligned with sustainable development goals.