www.webdeveloper.com
Results 1 to 7 of 7

Thread: If Statements input box

  1. #1
    Join Date
    Apr 2012
    Posts
    15

    If Statements input box

    I'm trying to get the php results of if statements into an input box. i tried using the $translateen as the value of the input shown below. but it does not work. i am very new to php and i would appreciate any help given.

    <?php
    $capseng = $_POST["english"];
    $capseng = strtolower($capseng);
    $english = $capseng;
    if ($english == "goodbye")
    echo "au revoir";

    elseif ($english =="Good day") ($translateen = "Bonjour");
    elseif ($english =="a") echo stripslashes("quelqu\'un, dans, un ");

    else
    echo "Not Found";
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <input type="text" name="english" maxlength="50" size="30"
    style="height: 42px; width: 233px" align="top" value="<?php echo $translateen;?>">
    </body>
    </html>

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Please don't get upset by my asking this question. I actually ran into this situation, once before.

    Is the document that you are working on saved as a .php file, or .html file?
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  3. #3
    Join Date
    Apr 2012
    Posts
    15
    it is saved as a php file.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Based on what I think you want to do, this fixes a few things and is a bit cleaner and clearer, I think:
    PHP Code:
    <?php
    $english 
    "";
    if(isset(
    $_POST["english"])){
        
    $english strtolower($_POST["english"]);
    }
    $translateen "";
    if (
    $english == "goodbye") {
        
    $translateen "au revoir";
    }
    elseif (
    $english =="good day") { // must be lower-case!
        
    $translateen "Bonjour";
    }
    elseif (
    $english =="a") {
        
    $translateen "quelqu'un, dans, un ";
    }
    elseif(
    $english !== "") {
        
    $translateen "Not Found";
    }
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <!-- need a form tag! -->
    <form action='' method='post'>
    <input type="text" name="english" maxlength="50" size="30"
    style="height: 42px; width: 233px" align="top" value="<?php echo $translateen;?>">
    </form>
    </body>
    </html>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Apr 2012
    Posts
    15
    wow thanks. that works perfectly, and I don't need the strip-slashes any more to display Apostrophes.

  6. #6
    Join Date
    Apr 2012
    Posts
    1
    What I can suggest you that make sure if you saved your file .php or not ..otherwise make it sure you put filename between inverted comma when you save file in any text editor.

  7. #7
    Join Date
    Apr 2012
    Posts
    15
    robotforce i clearly stated that i had saved it as a php file. The problem was resolved two days ago.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles