Jump to content

dataxspy

New Members
  • Posts

    2
  • Joined

  • Last visited

dataxspy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Basically nothing happens, I know clicking the button works and connecting to the db works but I'm unsure how to diagnose what is wrong with the javascript. It could be a syntax error but I've scanned for variable errors, wrong spelling. driver.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Website</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> </head> <body> <form method="POST"> <input type="text" id="search" size="2"> <input type="button" name="submit" id="submit" value="Search Drivers"> </form> <table id="tbl_driver" style="display:none"> <tr><th>Last Name</th><td id="Last_Name"></td></tr> <tr><th>First Name</th><td id="First_Name"></td></tr> </table> <script> $(document).ready(function() { $("#submit").click(function() { $.ajax({ url:"fetch.driver.info.php", type:"POST", data:{driver:$("#search").val()}, dataType:"JSON", success:function(data) { $("#tbl_driver").show(); $("#Last_Name").text(data.Last_Name); $("#First_Name").text(data.First_Name); alert( "Handler for .click() called." ); } }) }); }); </script> </body> </html> fetch.driver.info.php <?php require 'db.inc.php'; $id = $_POST["driver"]; $sql = "select * FROM Drivers WHERE Driver_ID = $id"; $query = mysqli_query($con,$sql); $data = array(); while($row=mysqli_fetch_array($query)) { $data['Last_Name']=$row['Driver_Last_Name']; $data['First_Name']=$row['Driver_First_Name']; } echo json_encode($data); ?> db.inc.php <?php $con = new mysqli("localhost","root","","United_Limousine"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); } ?>
  2. I tried using a for loop but I'm trying to think of a way to calculate interest for a number of years but after I have the amount of interest for one year I'm unsure of how to add the interest to the principle then calculate it again for the next year, to hold that number like $Principle + $Interest = $NewPrinciple then $NewPrinciple + $Interest for multiple years. <?php if (isset($_POST['submit'])) { $InvestmentFrequency = $_POST['InvestmentFrequency']; $CompoundFrequency = $_POST['CompoundFrequency']; $InitialInvestment = preg_replace("/[^0-9]/", '', $_POST['InitialInvestment']); $Contributions = preg_replace("/[^0-9]/", '', $_POST['Contributions']); $InvestmentLength = preg_replace("/[^0-9]/", '', $_POST['InvestmentLength']); $InterestRate = $_POST['InterestRate']; if ($InvestmentFrequency == "Weekly") { $InvestmentFrequency = "52"; } elseif ($InvestmentFrequency == "Monthly") { $InvestmentFrequency = "12"; } else { $InvestmentFrequency = "1"; } if ($CompoundFrequency == "Annually") { $CompoundFrequency = "1"; } elseif ($CompoundFrequency == "Semiannually") { $CompoundFrequency = "2"; } elseif ($CompoundFrequency == "Monthly") { $CompoundFrequency = "12"; } elseif ($CompoundFrequency == "Weekly") { $CompoundFrequency = "52"; } else { $CompoundFrequency = "365"; } if ($CompoundFrequency == "1") { $AdditionalInvestments = $Contributions * $InvestmentFrequency; $Principle = $InitialInvestment + $AdditionalInvestments; $Interest = $Principle * $InterestRate; $NewPrinciple = $Principle + $Interest; for ($x = 0; $x <= $InvestmentLength; $x++){ echo "$x - $NewPrinciple</br>"; } } } This is the output I get the principle and interest added together for the number of years I entered.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.