Jump to content

UaE

Members
  • Posts

    4
  • Joined

  • Last visited

UaE's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. how to make a sessions to see all process that I have done in the same page !?
  2. I almost solve it but have some wrongs. <!DOCTYPE html> <html> <head><title> test </title> </head> <body> <h1> Enter Comment </h1> <form action="" method="get"> Number1: <input type="text" name="num1"> Number2: <input type="text" name="num2"> <select name="cal"> <option value="+"> + </option> <option value="-"> - </option> <option value="/"> / </option> <option value="*"> * </option> </select> <input type="submit" value="Do Math"> </form> <?php $cal = ""; if(isset($_GET["cal"]) and isset($_GET["num1"]) and isset($_GET["num2"])) { if ( $_GET["cal"] == "+" ) echo (string)$_GET["num1"] ."+". (string)$_GET["num2"] ."=".((string)($_GET["num1"] + $_GET["num2"])); if ( $_GET["cal"] == "-" ) echo (string)$_GET["num1"] ."-". (string)$_GET["num2"] ."=".((string)($_GET["num1"] - $_GET["num2"])); if ( $_GET["cal"] == "/" ) echo (string)$_GET["num1"] ."/". (string)$_GET["num2"] ."=".((string)($_GET["num1"] / $_GET["num2"])); if ( $_GET["cal"] == "*" ) echo (string)$_GET["num1"] ."*". (string)$_GET["num2"] ."=".((string)($_GET["num1"] * $_GET["num2"])); } setcookie ("cal" , "" , time()+3600); echo $cal; ?> </form> </body> </html> If I entered 5 and 6 and press Do Math it will output 5+6=11 but If I do the process again the first output will disappear which is wrong !
  3. I changed it. but my problem is that I want Each time user press Do Math, it will be added to the screen like this php code: whenever you write the comment , it comes down when you press Add comment. This is my idea. this is my last code: <html> <head><title> test </title> </head> <body> <h1> Enter Comment </h1> <form action="a.php" method="get"> Number1: <input type="text" name="num1"> Number2: <input type="text" name="num2"> <select name="cal"> <option> + </option> <option> - </option> <option> / </option> <option> * </option> </select> <input type="submit" value="Do Math"> <?php $result= ""; if ( $_GET["cal"] == '+' ) $result = $_GET["num1"] ."+". $_GET["num2"] ."=". $_GET["num1"] + $_GET["num2"]; if ( $_GET["cal"] == '-' ) $reslut = $_GET["num1"] - $_GET["num2"] ."=". $_GET["num1"] - $_GET["num2"]; if ( $_GET["cal"] == '/' ) $result = $_GET["num1"] / $_GET["num2"] ."=". $_GET["num1"] / $_GET["num2"]; if ( $_GET["cal"] == '*' ) $result = $_GET["num1"] * $_GET["num2"] ."=". $_GET["num1"] * $_GET["num2"]; setcookie ("result" , "$result" , time()+3600); ?> </form> </body> </html>
  4. Hello, I have a problem writing a code in one file. It's a drop list having a different operation ( - + / * ) I have to select one of these and before that there are two text field to write two number. assuming I choosed ( * ) and write in number1: 12 and number2: 3 the output should be : 12 * 3 = 36 and it should appear in the same page (calculator page) here is a picture> this is my code and help me to improve it! <html> <head><title> test </title> </head> <body> <h1> Enter Comment </h1> <form action="new.php" method="get"> Number1: <input type="text" name="num1"> Number2: <input type="text" name="num2"> <select name="cal"> <option> + </option> <option> - </option> <option> / </option> <option> * </option> </select> <input type="submit" value="Do Math"> <?php $cal = ""; if ( $_GET["cal"] == + ) echo $_GET["num1"] ."+". $_GET["num2"] ."=". $_GET["num1"] + $_GET["num2"]; if ( $_GET["cal"] == - ) echo $_GET["num1"] - $_GET["num2"]; if ( $_GET["cal"] == / ) echo $_GET["num1"] / $_GET["num2"]; if ( $_GET["cal"] == * ) echo $_GET["num1"] * $_GET["num2"]; setcookie ("cal" , "" , time()+3600); ?> </form> </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.