Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using Functions

Posted on 2004-11-30
4
Medium Priority
?
544 Views
Last Modified: 2012-08-13
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML XMLNS="http://www.w3.org/1999/xhtml">
  <HEAD>
    <TITLE>
      Untitled
    </TITLE>
    <META HTTP-EQUIV="generator" CONTENT="PHP Designer 2005" />
  </HEAD>
  <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK=
  "#800080" ALINK="#FF0000">
    <?php

     /* If $radio (the action variable) is multiply then mutliply */
    if ($radio="multiply")
       {
       $number1 * $number2 == $answer
       print $answer
       }
    /* If $radio is divide then divide */
    elseif ($radio="divide")
     {
      $number1 / $number2 == $answer
      print $answer
    else
       {print This is not programmed yet}

    ?>
  </BODY>
</HTML>

How do I get that code to work. I know there are many errors but what am I doing wrong my php parser shows nothign wrong when I do a debug so I think it is broekn. I think you can tell what I want so how do I get it to do the divide and multiple using functions?
0
Comment
Question by:SkyvanMan
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:arantius
arantius earned 600 total points
ID: 12709129
SkyvanMan,
> my php parser shows nothign wrong
There is very much wrong.  You're not running the parser properly.  You're missing semicolons at the end of your statements.  Operators cannot appear on the left hand side of an assignment, and the assignment operator is =, == is the comparison operator.
0
 
LVL 18

Expert Comment

by:arantius
ID: 12709135
SkyvanMan,
>   {print This is not programmed yet}
You also need quotes around strings.  This should be

print "This is not programmed yet";
0
 
LVL 2

Accepted Solution

by:
b_loco earned 1400 total points
ID: 12709226
There were a lot of errors.

Here is the corrected code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML XMLNS="http://www.w3.org/1999/xhtml">
  <HEAD>
    <TITLE>
      Untitled
    </TITLE>
    <META HTTP-EQUIV="generator" CONTENT="PHP Designer 2005" />
  </HEAD>
  <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK=
  "#800080" ALINK="#FF0000">
    <?php

     /* If $radio (the action variable) is multiply then mutliply */
    if ($radio=="multiply"){
       $answer = $number1 * $number2;
       print $answer;
      } elseif ($radio=="divide"){
       $answer = $number1 / $number2;
       print $answer;
    } else{
            print "This is not programmed yet";
      }

    ?>
  </BODY>
</HTML>

I should say that this does nothing!
You don't have the $radio variable set.

However, if I understand what you are doing this should work:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML XMLNS="http://www.w3.org/1999/xhtml">
  <HEAD>
    <TITLE>
      Untitled
    </TITLE>
    <META HTTP-EQUIV="generator" CONTENT="PHP Designer 2005" />
  </HEAD>
  <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK=
  "#800080" ALINK="#FF0000">
    <?php

     /* If $radio (the action variable) is multiply then mutliply */
    if ($_POST['radio']=="multiply"){
       $answer = $_POST['number1'] * $_POST['number2'];
       print $answer;
      } elseif ($_POST['radio']=="divide"){
       $answer = $_POST['number1'] / $_POST['number2'];
       print $answer;
    } else{
            print "<form method=\"POST\" action=\"".$PHP_SELF."\">
                        Multiply?<input type=\"radio\" name=\"radio\" value=\"multiply\">
                        Divide?<input type=\"radio\" name=\"radio\" value=\"divide\"><br>
                        Number 1 <input type=\"text\" name=\"number1\">
                        Number 2 <input type=\"text\" name=\"number2\">
                        <input type=\"submit\" value=\"Go\">
                        </form>";
      }

    ?>
  </BODY>
</HTML>
0
 
LVL 5

Author Comment

by:SkyvanMan
ID: 12709304
Thank you all so much. I knew I was forgettin a lot of stuff. I am really new to PHP as you can see.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question