dongyuling0312 2017-02-24 08:23
浏览 65
已采纳

标准语法$ _POST ['']在解析变量之前返回false / drops数据

Sup stackies.

Okay, i have got a real head scratcher for you guys! I've been trying to solve this puzzle for a week now (apparently i was on stack cooldown). Ok so whats going on is that i have 2 scripts, that goes under the same if/elseif statement. They both work 100% individually (multiple tests were taken to conclude this). The script is supposed to start the if/elseif depending on one of 2 submit buttons. the scripts themselves is not the problem. It's the process of starting the scripts. On the same page as the 2 submit buttons, there is 2 "text" fields, that both of the scripts utilize to complete.

The buttons is build like this:

<input type="SUBMIT" Name="Udlaan"  VALUE="Udlån" METHOD="POST" class="Aside-Udlån">
<input type="SUBMIT" Name="Aflever"  VALUE="Aflever" METHOD="POST" class="Aside-aflever" >

They work.

The text fields are build like this:

<input Type="Text" Name="bunnr" Method="POST" Class="Skriv_bun" Placeholder="bun Nummer">
<input Type="Text" Name="Ordreren" Method="POST" Class="Ordre_No_Skriv" Placeholder="Ordre Nummer">

The variables that holds the data from the textfield looks like this:

$Ordre_Nr=$_POST['Ordreren'];
$bun_Nr=$_POST['bunnr'];

So the problem is that the data from the text field is never getting parsed into the variablesm, which causes my scripts to never run . (I mind you that the input fields and the variables are 3 lines apart with nothing inbetween nor above the textfields that has any relevance to this problem.) I added in or die($conn); on one of the variables, which gave me "Object of class mysqli could not be converted into string". Without it, the above just returns false with undefined index.

I tried making new scripts that is in no way connected to my real script. This is one of them:

<html>
  <head>
    <meta charset="UTF-8">
    <title>title</title>
  </head>
  <body>
  <form METHOD="POST">  <input type="submit" Method="POST" NAME="WORLD" Placeholder="World">
  <input type="text" Method="POST" NAME="Hello" Placeholder="hej">

  </form>
 <?php
 $f = $_POST['World'];
 $e = $_POST['hej'];
 if(isset($f)){echo $e;}
 ?>

  </body>
</html>

Do we agree that this should work? well it doesn't. Nothing, sip, nada. except the same "Undefined index". I made another quite like the one above(Almost exactly like it) using POST aswell, the data i put in the text field came out as GET (I could see everything in the url bar).

This isn't just a standard error, i had a guy with 20 years (on/off) of experience look at it, and he could not find a single syntax error, that could be related to this issue.

If anyone has any really good suggestions, please come forth and prevail! And should you be in need for more information, i will try my best to provide ^^

Fyi, i don't care much for "SQL injection comments, since it's not important for this issue. Fyi 2. This is NOT a duplicate. I have checked multiple questions with answers for this issue, nothing has worked.

  • 写回答

1条回答 默认 最新

  • douduoting8408 2017-02-24 08:29
    关注

    When using a form the method should only go into the <form> tag as shown in my example below:

    Note that I have used name="sendPost" as the name for submit button.

    <form method="post">
        <input type="text" name="world" placeholder="World">
        <input type="text" name="hello" placeholder="hej">
        <input type="submit" name="sendPost" value="Submit">
    </form>
    

    Then within the PHP you need to check if the sent has been submitted:

    <?php
    
    if (isset($_POST['sendPost']))
    {
        $f = $_POST['world'];
        $e = $_POST['hello'];
    
        echo $e, $f;
    }
    
    ?>
    

    Therefore, If isset sendPost (if sendPost has been pressed run this query)

    Also note, the PHP should go above the html rather than below.

    Added to:

    Else if's again run pretty simple, here's an addition to my initial answer:

    Take a form and add 2 submits instead of one.

    <form method="post">
        <input type="text" name="world" placeholder="World">
        <input type="text" name="hello" placeholder="hej">
        <input type="submit" name="sendPost" value="Submit">
        <input type="submit" name="reset" value="Reset Form">
    </form>
    

    Then within the PHP after your IF has closed you can run elseif (something else) such as my added example:

    <?php
    
    if (isset($_POST['sendPost']))
    {
        $f = $_POST['world'];
        $e = $_POST['hello'];
    
        echo $e, $f;
    } elseif (isset($_POST['reset']))
    {
        echo 'the form has been reset';
    }
    
    ?>
    

    Therefore, if sendPost has been submitted run whats within the brackets and echo out $e and $f. Else if you've pressed Reset run the echo of the form has been reset.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器