为什么if(isset($ _ POST ['accept']))无效?

时间:2014-01-29 03:06:46

标签: php html

我有小问题,我没有看到我的代码和服务器中的任何错误也没有返回任何错误但clouse if(isset($ _ POST ['accept']))无法识别该按钮被点击。它是获取按钮ID值的某种方式吗?请帮助。

            include '../../config.php';

            db_connect();

            $zapytanie = "SELECT * FROM messages ORDER BY message_id DESC";

            $r = mysql_query ($zapytanie) or die(mysql_error());

            $war="L".$_SESSION['lekarz_id'];
            echo $war;

            if (isset($_POST['accept']))
            {   
            echo "something";   
            }
            else{
            while ($row = mysql_fetch_array ($r))
            {

            if($war == $row['message_recipient'] AND !$row['message_title']=='LP' ){
            echo $war;

            print "<table border=2 width=98% align=center>
            <tr><td><font size=1><p align=left>Od: {$row['message_recipient']}</td> <td><p align=right>Wysłana: {$row['date_of_posting']}</align></font></td></tr>
            <tr><td><p align=left><font size=1>Do:{$row['message_sender']}</td><td><b><p align=right>Temat:{$row['message_title']}</align></b></td></tr>
            <tr><td colspan=2><br  /> {$row['message_text']}</align></font></td></tr>
            </table><hr  />";
            }

            else if($war == $row['message_recipient'] AND $row['message_title']=='LP'){

                echo "
                <form>
                <table border=2 width=80%>
                <tr>
                <td>Od:Wysłana: {$row['date_of_posting']}</td>
                <td><p align=center>Wysłana: {$row['date_of_posting']}</align></font></td>
                </tr>
                <tr>
                <td><p align=center><font size=5>Do:{$row['message_sender']}</td><td><b><p align=right>Temat:{$row['message_title']}</align></b>
                </td>
                </tr>
                <tr>
                <td ><br  /> <font size=5>{$row['message_text']}</align></font>
                </td>
                </tr>
                <tr>";
                $id = $row['message_sender'];
                $id=substr($id, -1);

                print'
                <td>
                <form action="messages.php"  method="post">
                <input type="submit" name="accept" value="accept" id=.{$id}./>
                </form>
                </td>
                <td> </td>
                </tr>
                </table>
                </form><hr  />
                ';



            }
            }
            db_close($db);
            }
            ?>

3 个答案:

答案 0 :(得分:3)

您没有将表单操作明确设置为POST。因此,您的表单值将通过GET发送。

变化:

<form>

<form method="POST">

或者在$_GET超全球中寻找你的价值。

if (isset($_GET['accept']))

您还在第二个表单中嵌入了一个表单。删除外部表单也可以解决您的问题。

答案 1 :(得分:0)

检查$_REQUEST['accept']。这结合了$_GET$_POST$_COOKIE。无论提交方法如何,它都将包含表单值。

http://www.php.net/manual/en/reserved.variables.request.php

答案 2 :(得分:0)

我还要提一下,使用提交按钮值发送参数不是一个好主意。如果您需要在按钮上写“接受”而不是“接受”,该怎么办?

对于此类按钮,

if ($_POST['accept']=='accept')将失败。更好的做法是使用隐藏字段name="accept"<input type="hidden" name="accept" value="any_value" />)并让提交按钮执行必须执行的操作 - 提交表单。

它还使您的表单可重用

<强> phpfidle