Hey guys well I figured out how to style a php echo, which was quite common sense, but instead having an ugly colored box just waiting for an answer, is there a way to just display the box when the user hits the calculation they want? my website - http://codepen.io/willc86/pen/BrEmt though php wont work, just have it for styling purpose, but I am sure you will understand the concept.
this is my php/html
<html>
<body>
<style><?php include "style.css" ?></style>
<form action="index.php" method="POST">
<table border="1">
<td>
<p>insert value one: <input type="text" name="num1"> <br>
<p>insert value two: <input type="text" name="num2"> <br>
</td>
<td>
<input type="submit" name="add" value="Addition">
<input type="submit" name="sub" value="Subtraction">
<input type="submit" name="mult" value="Multiplication">
<input type="submit" name="div" value="Division">
<input type="submit" name="all" value="Display All">
</td>
</table>
</form>
<div id="answer">
hello
<?php
if (isset($_POST['num1']) && ($_POST['num2'])){
$val1 = $_POST['num1'];
$val2 = $_POST['num2'];
$add = $val1+$val2;
$sub = $val1-$val2;
$mult = $val1*$val2;
$div = $val1/$val2;
}
if (isset($_POST['add'])){
echo $add;
}
?>
</div>
</body>
</html>
and this is my CSS
body{
background-color:#f0f0f0;
}
table{
margin:50px auto;
background-color: tan;
border: 2px solid black;
}
#answer{
margin:auto;
width:100px;
height: 100px;
background-color: tan;
text-align:center;
border: solid black 1px;
line-height: 100px;
}
Put your tags within your PHP's if condition, like this:
<?php
if (isset($_POST['num1']) && ($_POST['num2'])){
echo("<div id=\"answer\">");
$val1 = $_POST['num1'];
$val2 = $_POST['num2'];
$add = $val1+$val2;
$sub = $val1-$val2;
$mult = $val1*$val2;
$div = $val1/$val2;
if (isset($_POST['add'])){
echo $add;
}
echo("</div>");
}
?>