0

Hi,
I'm trying to code a PHP page with a textfield, a button and one link, every time I click in the button the value is added(sum) to a variable and when I click the link I can see the value of this variable somewhere in the page.

please help!

many thanks!!!

Edited by thumbcop: n/a

2
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by thumbcop
0
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <form action="index.php" method="POST">
        <input type="text" name="input_value">
        <input type="submit" name="submit">
        <body>
            <?php
            if (isset($_POST['submit'])) {
                $formvalue = $_POST['input_value'];
            }
            ?>
            
        </body>
</html>

Edited by thumbcop: n/a

0

OK, I just need to know how to run a code when I click a link.

0

its not working... (the sum) whats wrong?

<form action="index.php" method="POST">
        
        <input type="text" name="value_enter">
        <input type="submit" name="submit">
        <p> </p>

        <body>
            <?php
            
            if (isset($_POST['submit'])) {
                
                $value = $_POST['value_enter'];
                if ($value== 1){
                @$a = $a +1;      
                }
                echo @$a;

            }


            ?>
0

I'm trying to code a PHP page with a textfield, a button and one link, every time I click in the button the value is added(sum) to a variable and when I click the link I can see the value of this variable somewhere in the page.

can anyone do this code please?

Edited by thumbcop: n/a

0

Didn't anybody tell you patience is a virtue? 3 successive posts in just over an hour? That's a sure fire way of getting ignored.

Anyway:

<form action="index.php" method="POST">
 
        <input type="text" name="value_enter" />
        <input type="submit" name="submit" value="Send" />
        <p> </p>
 
        <body>
            <?php
 
            if (isset($_POST['submit'])) {
                $a = 0;
                $value = $_POST['value_enter'];
                if ($value== 1){
                $a = $a + 1;      
                }
                echo $a;
 
            }
 
 
 ?>

Anyway, your $a variable needs an initial value if you intend to add something to it.

0

Didn't anybody tell you patience is a virtue? 3 successive posts in just over an hour? That's a sure fire way of getting ignored.

Anyway:

<form action="index.php" method="POST">
 
        <input type="text" name="value_enter" />
        <input type="submit" name="submit" value="Send" />
        <p> </p>
 
        <body>
            <?php
 
            if (isset($_POST['submit'])) {
                $a = 0;
                $value = $_POST['value_enter'];
                if ($value== 1){
                $a = $a + 1;      
                }
                echo $a;
 
            }
 
 
 ?>

Anyway, your $a variable needs an initial value if you intend to add something to it.

Thank your for your reply.

it still doesn't work, I keep entering 1 in the textfield and the value doesn't increase...

1

Do you want a variable that remembers the last value? You can't do as above for an incrementer. You'll probably need to use a session variable or a cookie as web pages are stateless - they don't have a memory.

Or you could keep the running value in a form field - e.g. disabled textbox or a hidden field.

Edited by diafol: n/a

0

thank you I'm reading about cookies and session variable, I think I can go on from now... bye

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.