发布并在php中同时获取 [英] Post and get at the same time in php

查看:76
本文介绍了发布并在php中同时获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您对我的问题有任何建议吗?我需要同时使用get和post. 得到,因为我需要输出用户输入的内容.并发布,因为我需要访问与该输入相关的mysql数据库. 看起来像这样:

Do you have any suggestions with my problem. I need to use get and post at the same time. Get because I need to output what the user has typed. And post because I need to access the mysql database in relation to that input. It looks something like this:

<form name="x" method="get" action="x.php">
<input name="year" type="text">

<select name="general" id="general">
        <font size="3">
        <option value="YEAR">Year</option>

</form>

这将根据用户检查的内容输出mysql的内容:

This will output the contents of mysql depending on what the user will check:

<form name="y" method="post" action"y.php">
<input name="fname" type="checkbox">
</form>

这两个结合起来的形式动作看起来像这样:

And the form action of those two combined will look something like this:

   <?php

               if($_POST['general'] == 'YEAR'){
                   ?>
                   <?php echo $_GET["year"]; ?>
                   <?php
            $result2 = mysql_query("SELECT * FROM student
    WHERE student.YEAR='$syear'");
    ?>
    <table border='1'>
            <tr>

                    <?php if ( $ShowLastName ) { ?><th>LASTNAME</th><?php } ?>
                    <?php if ( $ShowFirstName ) { ?><th>FIRSTNAME</th><?php } ?>
        </tr>

    <?php while ( $row = mysql_fetch_array($result2) ) {
        if (!$result2)  { 

    }
        ?>
            <tr> 
                    <td><?php echo $row['IDNO']?> </td>
                    <td><?php echo $row['YEAR'] ?> </td>
     <?php if ( $ShowLastName ) { echo('<td>'.$row['LASTNAME'].'</td>'); } ?></td>
                    <?php if ( $ShowFirstName ) { echo('<td>'.$row['FIRSTNAME'].'</td>'); } ?>

当我这样做时,我确实收到很多未定义的错误.您可以建议我做些什么,以获取用户输入的值以及mysql数据.

I really get lots of undefined errors when I do this. What can you recommend that I should do in order to get the value inputted by the user together with the mysql data.

推荐答案

您只能拥有一个 HTTP请求.但是,您可以

You can only have one verb (POST, GET, PUT, ...) when doing an HTTP Request. However, you can do

<form name="y" method="post" action="y.php?foo=bar">

,尽管发送的请求已过POST,PHP也将填充$_GET['foo'].

and then PHP will populate $_GET['foo'] as well, although the sent Request was POST'ed.

但是,您的问题似乎更多是您正在尝试一次发送两种形式,针对两种不同的脚本.在一个请求中这是不可能的.

However, your problem seems to be much more that you are trying to send two forms at once, directed at two different scripts. That is impossible within one Request.

这篇关于发布并在php中同时获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆