Using 4 radio button as option to select the payment column to SUM all the number up. I wrote if select is equals to first then run first query, and if it's second to run second query. It's displaying on the first payment even if I select second. Is it because of my echo at the end of the code? Can anyone help please? Should be using for
?
HTML Coding (paycal.html):
<body>
<form name="input" action="paycal.php" method="post">
<fieldset>
<legend>Which payment do you want to SUM up:</legend>
<input type="radio" name="payment" value="first" /> First
<input type="radio" name="payment" value="second" /> Second
<input type="radio" name="payment" value="third" /> Third
<input type="radio" name="payment" value="fourth" /> Fourth
</fieldset>
<input type="submit" value="Submit" />
</form>
</body>
</html>
PHP Coding (paycal.php):
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$pay=$_REQUEST['payment'];
// MySQL database connection, username, password, database name
$con=mysqli_connect("localhost","username","password","database_name");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($pay=="first") $query="SELECT *, SUM(first_payment) FROM `Customer Information`";
else if ($pay=="second") $query="SELECT *, SUM(second_payment) FROM `Customer Information`";
else if ($pay=="third") $query="SELECT *, SUM(third_payment) FROM `Customer Information`";
else if ($pay=="fourth") $query="SELECT *, SUM(fourth_payment) FROM `Customer Information`";
$result = mysqli_query($query);
// Executing and error checking of query
if (!mysqli_query($con,$query)) {
die('Error: ' . mysqli_error($con));
}
while($row = mysqli_fetch_array($result)) {
echo $row['first_payment'];
}
// Close MySQL
mysqli_close($con);
?>