doulao1934 2012-09-11 05:47
浏览 13
已采纳

如何根据if语句指示html文件处理不同的php文件

I want to direct my html file based on the condition given by user in the front end (i.e. in the same html file itself).

Like if user enters code 789 it should direct to a specific folder u57.php and if it user enters 783 it should direct to the folder u38.php

i wrote a code, but it doesn't work properly...

$a = 57;
$b = 38;
$residue = $_POST["residue"];

<?php if($residue == "$a") { ?>
     <form method="POST" action="u57.php" enctype="multipart/form-data">
<?php } ?>

<?php if ($residue == "$b") { ?>
       <form method="POST" action="u38.php" enctype="multipart/form-data">
    <?php } ?>   

Its directing to only the same page u57.php, if user enters 38 or any other number like 40, 45, 1 ,2 . Please tell me whats wrong with my code?

  • 写回答

2条回答 默认 最新

  • drnxnbf199049 2012-09-11 06:05
    关注

    Hope this Works, (Just removed the Double Quotes for Condition Check)

    $a = 57;
    $b = 38;
    $residue = $_POST["residue"];
    
    <?php if($residue == $a) { ?>
         <form method="POST" action="u57.php" enctype="multipart/form-data">
    <?php } ?>
    
    <?php if ($residue == $b) { ?>
           <form method="POST" action="u38.php" enctype="multipart/form-data">
        <?php } ?> 
    
    • UPDATE

    Here is the sample i did,

    INDEX.PHP

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title></title>
        </head>
        <body>
            <form method="POST" action="redirect.php">
                Value : <input type="text" name="residue" value=""/>
                <input type="submit" name="submit" value="Submit"/>
            </form>
        </body>
    </html>
    

    REDIRECT.PHP

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title></title>
        </head>
        <body>
            <?php
            $a = 57;
            $b = 38;
            $residue = $_POST["residue"];
            ?>
            <?php if ($residue == $a) {
                ?>
                <form method="POST" action="u57.php" enctype="multipart/form-data">
                    <input type="text" name="sample" value=""/>
                </form>
            <?php } ?>
    
            <?php if ($residue == $b) { ?>
    

    This Works for me....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持