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

查看:20
本文介绍了在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.

推荐答案

你只能拥有一个 动词 (POST, GET, PUT, ...) 在执行 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">

然后 PHP 也会填充 $_GET['foo'],尽管发送的请求是 POST 的.

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天全站免登陆