<Html> <Head> <Title> PHP implements a simple calculator </title> <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"> </Head> <? Php $ Num1 = true; $ Num2 = true; $ Numa = true; $ Numb = true; $ Message = ""; // Single Branch If (isset ($ _ GET ["sub"]) { If ($ _ GET ["num1"] = ""){ $ Num1 = false; $ Message. = "The first number cannot be blank "; } If (! Is_numeric ($ _ GET ["num1"]) { $ Numa = false; $ Message. = "The first number is not a number "; } If ($ _ GET ["num2"] = ""){ $ Num2 = false; $ Message. = "The second number cannot be blank "; } If (! Is_numeric ($ _ GET ["num2"]) { $ Numb = false; $ Message. = "The second number is not a number "; } If ($ num1 & $ num2 & $ numa & $ numb ){ $ Sum = 0; // Multiple branch switches Switch ($ _ GET ["ysf"]) { Case "+ ": $ Sum = $ _ GET ["num1"] + $ _ GET ["num2"]; Break; Case "-": $ Sum = $ _ GET ["num1"]-$ _ GET ["num2"]; Break; Case "x ": $ Sum = $ _ GET ["num1"] * $ _ GET ["num2"]; Break; Case "/": $ Sum = $ _ GET ["num1"]/$ _ GET ["num2"]; Break; Case "% ": $ Sum = $ _ GET ["num1"] % $ _ GET ["num2"]; Break; } } } ?> <Br/> <B> Notice </B>: Undefined index: num1 in <B> D: \ php \ PHPnow1.5.5 \ Package \ vhosts \ 127.0.0.1 \ ceshi \ jsq. php </B> On line <B> 64 </B> <br/> <Body> <Table align = "center" border = "1" width = "500"> <Caption> <Form action = "jsq. php"> <Tr> <Td> <Input type = "text" size = "5" name = "num1" value = "<? Php echo $ _ GET ["num1"]?> "> </Td> <Td> <Select name = "ysf"> <Option value = "+" <? Php if ($ _ GET ["ysf"] = "+") echo "selected"?> + </Option> <Option value = "-" <? Php if ($ _ GET ["ysf"] = "-") echo "selected"?> -</Option> <Option value = "x" <? Php echo $ _ GET ["ysf"] = "x "? "Selected": ""?> X </option> <Option value = "/" <? Php echo $ _ GET ["ysf"] = "/"? "Selected": ""?> /</Option> <Option value = "%" <? Php echo $ _ GET ["ysf"] = "% "? "Selected": ""?> % </Option> </Select> </Td> <Td> <Input type = "text" size = "5" name = "num2" value = "<? Php echo $ _ GET ["num2"]?> "> </Td> <Td> <Input type = "submit" name = "sub" value = "computing"> </Td> </Tr> <? Php If (isset ($ _ GET ["sub"]) { Echo '<tr> <td colspan = "5"> '; If ($ num1 & $ num1 & $ numa & $ numb ){ Echo "result :". $ _ GET ["num1"]. "". $ _ GET ["ysf"]. "". $ _ GET ["num2"]. "= ". $ sum; } Else { Echo $ message; } Echo '</td> </tr> '; } ?> </Form> </Table> </Body> </Html> |