Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
oleibman and Owen Leibman committed Sep 5, 2024
1 parent 50ec30b commit 5c931e9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions samples/Basic4/45_Quadratic_equation_solver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
?>
<form action="45_Quadratic_equation_solver.php" method="POST">
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
Enter the coefficients for Ax<sup>2</sup> + Bx + C = 0
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Expand Down Expand Up @@ -47,7 +47,9 @@
<?php
/** If the user has submitted the form, then we need to execute a calculation * */
if (isset($_POST['submit'])) {
if ($_POST['A'] == 0) {
if (!is_numeric($_POST['A']) || !is_numeric($_POST['B']) || !is_numeric($_POST['C'])) { // validate input
$helper->log('Non-numeric input');
} elseif ($_POST['A'] == 0) {
$helper->log('The equation is not quadratic');
} else {
// Calculate and Display the results
Expand Down

0 comments on commit 5c931e9

Please sign in to comment.