Skip to content

Commit 5c931e9

Browse files
oleibmanOwen Leibman
andauthored
Merge commit from fork
* Validate POST Input in Sample 45 Errors will result if inputs are not numeric. * Update 45_Quadratic_equation_solver.php --------- Co-authored-by: Owen Leibman <[email protected]>
1 parent 50ec30b commit 5c931e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

samples/Basic4/45_Quadratic_equation_solver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
?>
1616
<form action="45_Quadratic_equation_solver.php" method="POST">
17-
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
17+
Enter the coefficients for Ax<sup>2</sup> + Bx + C = 0
1818
<table border="0" cellpadding="0" cellspacing="0">
1919
<tr>
2020
<td>
@@ -47,7 +47,9 @@
4747
<?php
4848
/** If the user has submitted the form, then we need to execute a calculation * */
4949
if (isset($_POST['submit'])) {
50-
if ($_POST['A'] == 0) {
50+
if (!is_numeric($_POST['A']) || !is_numeric($_POST['B']) || !is_numeric($_POST['C'])) { // validate input
51+
$helper->log('Non-numeric input');
52+
} elseif ($_POST['A'] == 0) {
5153
$helper->log('The equation is not quadratic');
5254
} else {
5355
// Calculate and Display the results

0 commit comments

Comments
 (0)