0
How to run php code with html form in solo learn compiler
I have created a simple calculator in Php which require user input from HTML form but When i run it in solo learn editor it shows nothing. Can anyone help me.
7 Respostas
+ 4
Missing closing php tag
?>
before the closing body tag.
+ 3
Show your code please.
+ 3
Code Playground cannot fully support php form submission.
+ 1
And this code is running fine in pc
+ 1
Really thanks for your support.
0
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form>
<input type="text" name="num1"placeholder="Number 1"></br>
<input type="text" name="num2"placeholder="Number 2"></br>
<select name="operator">
<option>None</option>
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Divide</option>
</select></br>
<button type="submit" name="submit">
Calculate
</button>
</form></br></br>
<p>Here is your Answere</p></br>
<?php
if(isset($_GET['submit'])){
$result1 = $_GET['num1'];
$result2 = $_GET['num2'];
$operator = $_GET['operator'];
switch ($operator){
case 'None':
echo "Select Something";
break;
case "Add":
echo $result1 + $result2;
break;
case "Subtract" :
echo $result1 - $result2;
break;
case "Multiply" :
echo $result1 * $result2;
break;
case "Divide":
echo $result1 / $result2;
}
}
</body>
</html>
0
Thanks but it still not working
showing error 'unexpected if'
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form>
<input type="text" name="num1"placeholder="Number 1"></br>
<input type="text" name="num2"placeholder="Number 2"></br>
<select name="operator">
<option>None</option>
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Divide</option>
</select></br>
<button type="submit" name="submit">
Calculate
</button>
</form></br></br>
<p>Here is your Answere</p></br>
<?php
if(isset($_GET['submit'])){
$result1 = $_GET['num1'];
$result2 = $_GET['num2'];
$operator = $_GET['operator'];
switch ($operator){
case 'None':
echo "Select Something";
break;
case "Add":
echo $result1 + $result2;
break;
case "Subtract" :
echo $result1 - $result2;
break;
case "Multiply" :
echo $result1 * $result2;
break;
case "Divide":
echo $result1 / $result2;
}
}
?>
</body>
</html>