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!!!

Recommended Answers

All 9 Replies

Member Avatar for diafol

This sounds like a job for javascript.

Show us your code so far.

<!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>

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

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;

            }


            ?>

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?

Member Avatar for diafol

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.

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...

Member Avatar for diafol

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.