-1

I have a form like the following:

<form action="campionat.php?competitii='.$idcompetitie.'">
    <input type="submit" name="upgrade" value="inainte" />
</form>

On campionat.php:

    if($_POST['upgrade']=="inainte")
    {    
        $lvlupstadion   = $levelstadio+1;
        $cost               = 10000000*$lvlupstadion;
        $bugetnou       = $buget - $cost;

        $q = mysql_query("UPDATE echipa SET levelstadion='".$lvlupstadion."' , buget='".$bugetnou."' WHERE (`echipa`='".$echipa."') AND (`user`='".$id."') AND (`competitie`='".$competitie."')") ;
        if (!$q)
        {
            echo  mysql_error($q);
        }
        echo $lvlupstadion.$bugetnou.$echipa.$id.$competitie;
    }

Why my database does not change and my script doesn't alert me about errors?

Ander2
  • 5,569
  • 2
  • 23
  • 42

5 Answers5

2

The default method of a <form> tag is GET.

Since your form has no method specified, it'll send a get. In which case $_POST['upgrade'] is not available.

If you change

<form action="campionat.php?competitii='.$idcompetitie.'">
    <input type="submit" name="upgrade" value="inainte" />
</form>

to

<form method="post" action="campionat.php?competitii='.$idcompetitie.'">
    <input type="submit" name="upgrade" value="inainte" />
</form>

it should work.

Please refer to this question: What is the default form HTTP method?

Community
  • 1
  • 1
MisterBla
  • 2,355
  • 1
  • 18
  • 29
1

Your form does not have a method, therefore it will default to GET. This is a problem because you are trying to access $_POST['upgrade'] which will never be set.

Set the method to post.

<form method="post" ... >

From W3C docs:

method

Possible (case-insensitive) values are "get" (the default) and "post"

Community
  • 1
  • 1
MrCode
  • 63,975
  • 10
  • 90
  • 112
1

Your form is missing things . You have to choose between $_GET and $_POST. + What are you doing with $q?

Loko
  • 6,539
  • 14
  • 50
  • 78
0

If

(`user`='".$id."')

Is an ID (int) you don't need simple quote. It might help you

marshallino16
  • 2,645
  • 15
  • 29
0

Store the value in hidden field and then send it to another page

<form action="campionat.php" method="post">
<input type="hidden" name="competitii" value="<?php echo $idcompetitie; ?>">
<input type="submit" name="upgrade" value="inainte" />
</form>

your redirection is not sending the value from form post method.

Afsar
  • 3,104
  • 2
  • 25
  • 35
  • 1
    Moving the id from the url (form action) to a hidden field does not address the original error (which is corrected by this answer, but not mentioned). – AD7six Jun 26 '13 at 08:36