Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post

    Get Result in html

    Dear sir my html file has following coedes
    Code:
    <Html>
    <head>
    <title>Add two numbers on same form</title>
    <body>
    <center>
    <h1><font color="blue"> Sum Two Numbers</font></h1>
    <form name="thisform" method="Get" action="getsum2.php">
    <table cellpadding=3 cellspacing=3>
    <tr>
    <td>Enter First Number</td><td><input type="Text" name="text1"></td>
    </tr>
    
    <tr>
    <td>Enter Second Number</td><td><input type="Text" name="text2"></td>
    </tr>
    <tr>
    <td style="color: #ff0000">Result</td><td><input type="Text" name="text2" disabled></td>
    </tr>
    
    <tr>
    <td colspan=2 align="center"><input type="Submit" Value="Result"></td>
    </tr>
    </table>
    </center>
    </body>
    </html>
    And getsum2.PHP file has these codes

    Code:
    <?php
    $num1=$_GET['text1'];
    $num2=$_GET['text2'];
    $result=$num1+$num2;
    echo "Result= $result";
    ?>

    These both file works fine. The result is show in getsum2 php.
    But I want to get result in sum2.html's text3.

    Both files are in attachment.

    Please help
    Attached Files Attached Files

  • #2
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    
    <Html>
    <head>
    <title>Add two numbers on same form</title>
    
    <?php
    
    $num1=$_GET['text1'];
    $num2=$_GET['text2'];
    $result=$num1+$num2;
    ?>
    
    <body>
    <center>
    <h1><font color="blue"> Sum Two Numbers</font></h1>
    <form name="thisform" action="sum2.html" method="GET">
    <table cellpadding=3 cellspacing=3>
    <tr>
    <td>Enter First Number</td><td><input type="Text" name="text1"></td>
    </tr>
    
    <tr>
    <td>Enter Second Number</td><td><input type="Text" name="text2"></td>
    </tr>
    <tr>
    <td style="color: #ff0000">Result</td><td><input type="Text" name="text2" value="<?php echo $result; ?> ";disabled></td>
    </tr>
    
    <tr>
    <td colspan=2 align="center"><input type="Submit" Value="Result"></td>
    </tr>
    </table>
    </center>
    
    
    
    </body>
    </html>
    
    Gojavo.com
    Tell if that works, if it works give me a thanks and head over to my search engine I created at gojavo[dot]com

    PS, any php code you use inside a page it's good practice to have that page extinction a .php not .html

  • #3
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts
    be sure to add the </HEAD> tag below the php code since I did not include it in the above.

  • #4
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post
    Sir you codes does not work.

    When I enter values in text1 and text2 and then press result button all values disapperas.

  • #5
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Try to do a print_r() to find out the error it could be the way your php.ini file is set up then post the results

  • #6
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I posted the same code up on my server located here

    http://gojavo.com/drone/example.php

    It works perfectly. It could be the way your server files are set up

  • #7
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Here try this new code this should work.

    Code:
    <Html>
    <head>
    <title>Add two numbers on same form</title>
    
    <?php
    
    
    $result=$text1[0]+$text1[1];
    
    ?>
    
    <body>
    <center>
    <h1><font color="blue"> Sum Two Numbers</font></h1>
    <form name="thisform" action="http://gojavo.com/drone/example.php" method="GET">
    <table cellpadding=3 cellspacing=3>
    <tr>
    <td>Enter First Number</td><td><input type="Text" name="text1[]"></td>
    </tr>
    
    <tr>
    <td>Enter Second Number</td><td><input type="Text" name="text1[]"></td>
    </tr>
    <tr>
    <td style="color: #ff0000">Result</td><td><input type="Text" name="text3" value="<?php echo $result; ?> ";disabled></td>
    </tr>
    
    <tr>
    <td colspan=2 align="center"><input type="Submit" Value="Result"></td>
    </tr>
    </table>
    </center>
    
    
    
    </body>
    </html>
    
    Gojavo.com

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    I know I've answered this before. But I'll submit here:
    PHP Code:
    <?php
    $first 
    '';
    $sec '';
    $res '';
    $message1 '';
    if(isset(
    $_GET['reset'])){
        
    $first '';
        
    $sec '';
        
    $res '';
        
    $message1 '';
    }else{
        if(isset(
    $_GET['text1']) && isset($_GET['text2'])) {
            
    $tag 1;
            
    $first $_GET['text1'];
            
    $sec $_GET['text2'];
            if(!
    is_numeric($first)){
                
    $message1 "This must be a number";
                
    $first $message1;
                
    $tag 2;
            }
            if(!
    is_numeric($sec)){
                
    $message1 "This must be a number";
                
    $sec $message1;
                
    $tag 2;
            }
            if(
    $tag == 1){
                
    $res $_GET["text1"] + $_GET["text2"];
            }
        }
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title>Add two numbers on same form</title>
    <style type="text/css">
    body{
        width: 960px;
    }
    #here{
        width: 300px;
        height: 200px;
        margin: 0 auto;
    }
    h1{
        color: blue;
    }
    input{
        float:right;
    }
    label{
        float:left;
    }
    button{
        margin-top: 5px;
    }
    <?php if($tag == 2){
    echo 
    "input{color: red;}";
    }
    ?>
    </style>
    </head>

    <body>
    <div id="here">
        <form method="get" action="#" accept>
            <h1>Sum Two Numbers</h1>
    <p>
            <label for="text1">Enter First Number</label>
            <input type="text" name="text1" value="<?= $first?>">
    </p>
    <p>
            <label for="text2">Enter Second Number</label>
            <input type="text" name="text2" value="<?= $sec?>">
    </p>
    <p>
            <label for="result">Result</label>
            <input type="text" name="result" value="<?= $res?>" disabled>
    </p><br />

    <div style="margin-top:55px;">
        <input type="submit" value="Calculate" style="float:left;">
        <input type="submit" name="reset" value="Reset">
    </div>

        </form>
    </div>
    </body>
    </html>
    Evolution - The non-random survival of random variants.

  • #9
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post
    Sir it showing error in this line of code

    Code:
    <form method="get" action="#" accept>

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    @tqmd1, Your probably right. It doesn't show up for me, but at a glance I know why. accept is not accepted in HTML5. Just remove it, it should not have been there.
    Evolution - The non-random survival of random variants.


  •  

    Posting Permissions

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