$ _POST无法正常工作

时间:2015-09-14 15:01:50

标签: php html css

我正在尝试运行以下查询,基本上创建一个提交按钮。但是,当我尝试单击“接受请求”按钮时,它不会解析if条件并直接回显在else条件下写入的内容。 有人能帮助为什么会发生这种情况吗?

<dependencies>
    <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>${checkstyle.version}</version>
    </dependency>    
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.16</version>
                <dependencies>
                    <dependency>
                        <groupId>com.example.hello</groupId>
                        <artifactId>domain-module</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>validate</id>
                        <phase>validate</phase>
                        <configuration>
                            <configLocation>domain-module/src/main/resources/checkstyle.xml</configLocation>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>false</failsOnError>
                            <failOnViolation>true</failOnViolation>
                            <violationSeverity>warning</violationSeverity>
                            <logViolationsToConsole>true</logViolationsToConsole>
                            <skip>false</skip>
                        </configuration>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <...>
        </build>
    </pluginManagement>
</plugins>

2 个答案:

答案 0 :(得分:0)

Maybe You haven't set all variables. Try to define that and use: $

So create something like: $acceptrequest == something

答案 1 :(得分:0)

In general, you ought not use variables to define the name of a form input.

Specifically because of the "variable" nature of variables, you can't be sure that the name posted will match the name you're looking for.

In order to keep your application stateless, you should instead post the variable kn its own hidden input.

Below, I modified your form to post user_from as its own input, separate from acceptrequest and ignorerequest.

This should fix any state issues that you were experiencing before.

<?php
  if (isset($_POST['acceptrequest')) {
      echo "You are now friend with {$_POST['user_from']}!";
  } else if (isset($_POST['ignorerequest')) {
      echo "You ignored the request from {$_POST['user_from']}!";
  } else {
      echo 'Error in reading - acceptrequest'.$user_from;
  }
?>


<form action = "friend_request.php" method="POST">
<input type="hidden" name="user_from"
       value="<?php echo $user_from;?>" />
<input type="submit" name="acceptrequest"   
       value="Accept Request" style = "margin-left: 5px;" />
<input type="submit" name="ignorerequest"  
       value="Ignore Request" style = "margin-left: 5px;" />
</form>