PHP表单数据在提交时未存储?

时间:2013-04-23 08:50:45

标签: php mysql forms

我正在使用同义词/别名管理器数据库,用户可以在其中存储他们认为正确的关联。假设用户键入“rabbit”并且未找到任何同义词或别名。然后用户决定将“兔子”与“兔子”相关联并将其存储到数据库中。任何其他用户在“兔子”中输入“兔子”的结果时,都会出现。但是,我正在尝试实现一个轮询系统,询问用户是否认为关联是正确的。如果他们认为“兔子”适合“兔子”,那么他们投赞成票,否则不投票。这是我被困的地方。加载轮询并按提交后,所有内容都会消失,并且不会将任何内容发送到数据库。代码如下:

$query = "SELECT * from searchtestdb where engname in ( SELECT synonyms.synonym  FROM words  LEFT JOIN synonyms ON synonyms.word_id = words.word_id WHERE word LIKE '%$searchBox%') "; // Query for animals in db
        $query = mysql_query($query);

        if(mysql_num_rows($query) == 0)
        {
            echo "<h2>Aliases: </h2>";
            echo "Sorry, but we can not find an alias to match your query.";
            echo "<br> ";

        }
        else        
        {
            echo "<h2> Results using Alias: </h2>";
            while($result = mysql_fetch_array($query)) 
            {
                $query2 = "SELECT * from searchtestdb where engname LIKE '%".$result['engname']."%';";
                $result2 = mysql_query($query2);
                while($row = mysql_fetch_array($result2)) 
                {
                    print "<h4>Latin Name: </h4> ";
                    echo $row["latname"];
                    echo "<br> "; 
                    print"<h4>English Name:</h4> ";
                    echo $row["engname"];
                    echo "<br>"; 
                    print "<h4> Species: </h4> ";
                    echo $row["spectype"];
                    print "<h4>Characteristics: </h4> ";
                    echo $row["charc1"];
                    echo "<br>"; 
                    echo $row["charc2"];
                    echo "<br>"; 
                    echo $row["charc3"];
                    echo "<br>"; 

                }

            }
            $self = $_SERVER['PHP_SELF'];
            print "<form method='post' action='$self' >\n";
            print "<h4>Alias Association Correct? : </h4>";
            print "<p>" . 
                  "<input type='radio' name='vote' id='vote' value='1' /> \n" .
                  "Yes" .
                  "<input type='radio' name='vote' id='vote' value='2' /> \n" .
                  "No" .
                  "</p> \n" .
                  "<p>" .
                  "<input type='submit'name='submitVote' value='Submit' />" .
                  "\n </p> \n" .
                  "</form> \n" .
                  $vote=htmlentities($_POST['vote']);
                  echo $vote;

            mysql_connect(----------------------) or die(mysql_error()); 
            mysql_select_db("-----------") or die(mysql_error());       

            if($vote == 1)
            { 
                mysql_query("INSERT INTO items(yes, uNo, word_id) VALUES ('0', '0', bunny');");
                mysql_query("UPDATE items SET yes=yes+1 WHERE word_id='bunny';"); 
                echo 'Thanks for voting Yes!'; 
            } 
            if($vote == 2)
            {   mysql_query("INSERT INTO items(word_id) VALUES ('".$result['engname']."'') ");
                mysql_query("UPDATE items SET uNo=Uno+1 WHERE word_id='".$result['engname']."'");
                echo "changos";
            }

        }

1 个答案:

答案 0 :(得分:0)

简而言之,我犯了一个小错误:

$self = $_SERVER['PHP_SELF'];

应该是

$self = $_SERVER['POST'];

非常感谢。