Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

If is not working (Noob question)

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

If is not working (Noob question)

Postby AFakeman » Tue Jul 02, 2013 2:09 am

I am a total newb to PHP, and tried to make a calculator.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Тег input, атрибут type</title>
</head>
<body>
<?php
$num1 = (int)$num1;
$num2 = (int)$num2;
echo "lol"
if ($action == "a") then
{$result = $num1 + $num2;}
elseif ($action == "s") then
{$result = $num1 - $num2;}
elseif ($action == "m") then
{$result = $num1 * $num2;}
elseif ($action == "d") then
{$result = $num1/$num2;};
echo $result;
?>
</body>
</html>
Script isn't working at all. Why?
AFakeman
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 02, 2013 1:52 am

Re: If is not working (Noob question)

Postby pbs » Tue Jul 02, 2013 2:25 am

how you are getting (int)$num1, (int)$num2 and $action values, it is through GET or POST
pbs
New php-forum User
New php-forum User
 
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India

Re: If is not working (Noob question)

Postby AFakeman » Tue Jul 02, 2013 2:34 am

GET
UPD: here is form html page:
<form action="action.php" name ="calculate" method="get">
<p> <input type = "radio" name="action" value="a"> Add </p>
<p> <input type = "radio" name="action" value="m"> Multiply </p>
<p> <input type = "radio" name="action" value="s"> Substract </p>
<p> <input type = "radio" name="action" value="d"> Divide </p>
<p> <input type = "text" name="num1"> Number 1 </p>
<p> <input type = "text" name="num2"> Number 2 </p>
<p> <input type = "submit"> </p>
</form>
AFakeman
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 02, 2013 1:52 am

Re: If is not working (Noob question)

Postby pbs » Tue Jul 02, 2013 3:22 am

use $_GET to get values for $num1, $num2 and $action variable like this


Code: Select all
$num1 = int $_GET['num1'];
$num2 = int $_GET['num2'];
$action = $_GET['action'];
pbs
New php-forum User
New php-forum User
 
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India

Re: If is not working (Noob question)

Postby AFakeman » Tue Jul 02, 2013 5:04 am

By some reasons, still nothing. Even debug echo is not working when if part is uncommented.
AFakeman
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 02, 2013 1:52 am

Re: If is not working (Noob question)

Postby johnj » Mon Jul 08, 2013 11:57 pm

First - try to get the values from the submitted form
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.