Jump to content

bogdanserban3105

New Members
  • Posts

    3
  • Joined

  • Last visited

bogdanserban3105's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. the red square is where i wanted to see the calculated results but this is all it displays all the time
  2. So, the app I try to code it's for a school project, but the teacher failed to explain anything and wanted a working app in 2 days from now. I chose to make an electromagnet calculator but I don't understand why it doesn't work, from my point of view I wrote the code correctly but when I press the calculate button nothing happens. Most of the line codes are normal HTML and equations written in PHP, the two functions I made are for checking the closest value to the calculated dcu from a database that contains 2 columns: dcu and dcuiz, after that store them inside the dcu and dcuiz variables. At the end i want the program to display the d1,d2,d3,h,g and N variables, but the text is always displayed as "echo $ d1 ....", not as i wanted to show the calculated values. Please help and thank you in advance for helping me <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Calculator electromagnet</title> <div class="ele-calculator"> <a href="https://imgbb.com/"><img src="https://i.ibb.co/hZLHzMG/download.png" alt="download" border="0" /></a> <h2>Calculator electromagnet</h2> <section> <fieldset> <div class="row"> <label for="ele-raport">Raportul h/(d2-d1)</label> <select id="ele-raport" class="ele-raport" name="ele-raport"> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> <div class="row ele-inductie-row"> <label for="Inductia">Inductia (T)</label> <input type="text" id="ele-inductie" class="ele-inductie" name="ele-inductie" size="2" maxlength="10" value="" /> </div> <div class="row ele-forta-row"> <label for="ele-forta">Forta (N)</label> <input type="text" id="ele-forta" class="ele-forta" name="ele-forta" size="2" maxlength="10" value="" /> </div> <div class="row"> <label for="ele-intrefier">Intrefierul (mm)</label> <input type="text" id="ele-intrefier" class="ele-intrefier" name="ele-intrefier" size="2" maxlength="10" value="" /> </div> <div class="row last"> <input type="submit" id="ele-calc" class="ele-calc" name="ele-calc" value="Calculeaza" /> </div> </fieldset> </section> </div> </head> <body> <?php // Function to get the closest value of dcu to the calculated one function closestValueTo($calculated_dcu, $db_file) { $db = new SQLite3($db_file); $query = "SELECT dcu FROM table ORDER BY ABS(dcu - $calculated_dcu) LIMIT 1"; $results = $db->query($query); if($results){ $row = $results->fetchArray(); return $row['dcu']; } else { return null; } } // Function to get a specific value from the database function getValueFromDB($dcu, $db_file, $column) { $db = new SQLite3($db_file); $query = "SELECT $column FROM table WHERE dcu = '$dcu'"; $results = $db->query($query); if($results){ $row = $results->fetchArray(); return $row[$column]; } else { return null; } } if(isset($_GET['ele-calc'])){ $Forta = $_GET['ele-forta']; // value for Forta $Inductia = $_GET['ele-inductie']; // value for Inductia $Intrefierul = $_GET['ele-intrefier']; // value for Intrefierul $mSelect = $_GET['ele-raport']; if ($mSelect === '3') { $raport = 3; } if ($mSelect === '4') { $raport = 4; } if ($mSelect === '5') { $raport = 5; } // Equation A1 $A1 = (2* 1.257*pow(10,-6)*$Forta)/pow($Inductia, 2); // Equation d1 $d1 = sqrt((4*$A1)/3.14); // Equation A1 (repeated) $A1 = (pow($d1, 2)* 3.14)/4; // Equation F1 $F1 = ($A1*pow($Inductia, 2))/ (2* 1.257*pow(10,-6)); // Equation Sol $Sol = ($Inductia * $Intrefierul) / ( 0.7 * 1.257*pow(10,-6)); // Equation h $h = pow (((5* 2.115 * pow (10, -8) * pow ($Sol, 2) * 0.5)/(2*4*40/100* 40), 1/3)); // Equation d2 $d2 = $h/$raport – $d1; // Equation d3 $d3 = sqrt((pow($d1, 2)/0.8 + pow($d2,2))); // Equation g $g = $d2 – $d1; // Equation dcu $dcu = sqrt((4* 2.115 * pow (10, -8) * ($d1 + $d2) * $Sol)/ 24); // Compare DCU with values from a .db file $dcuiz = closestValueTo($dcu, 'sarma.db'); // Get dcuiz from database $dcuiz = getValueFromDB($dcuiz, 'sarma.db', 'dcuiz'); // Equation Nst $Nst = $h/$dcuiz; // Equation N $N = (4*40/100 * $g* $h)/ 3.14 * pow($dcu); echo "d1: " . $d1 . "<br>"; echo "d2: " . $d2 . "<br>"; echo "d3: " . $d3 . "<br>"; echo "g: " . $g . "<br>"; echo "h: " . $h . "<br>"; echo "N: " . $N . "<br>"; } ?> <form> <!-- Form fields and submit button go here --> <div id="result" style="display:none;"></div> </form> <script> document.getElementById("ele-calc").addEventListener("click", function(){ if(isset($_GET['ele-calc'])){ // Code for calculating variables, such as $d1, $d2, $d3, $g, $h, and $N var result = "d1: " + <?php echo $d1; ?> + "<br> d2: " + <?php echo $d2; ?> + "<br> d3: " + <?php echo $d3; ?> + "<br> g: " + <?php echo $g; ?> + "<br> h: " + <?php echo $h; ?> + "<br> N: " + <?php echo $N; ?>; document.getElementById("result").innerHTML = result; document.getElementById("result").style.display = "block"; } }); </script> </body> </html>
×
×
  • 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.