【问题标题】:Manually Send Data PHP method post手动发送数据 PHP 方法帖子
【发布时间】:2022-01-01 04:21:47
【问题描述】:

我是巴西人,我做了一个简单的网站来发送简单的用户数据,但要进行测试,我想在链接中手动发送更新的数据,如果它运行不需要完整的手动表格,那么我可以直接通过我的应用程序使用保存所有用户数据。

看看我的想法:

mywebsite.com/savedata?method=post&usernamesave=Nome&Misael&userxp=34&userid=35&userlevel=31&usermail=crod%40gmail.com&userprog1=1&userprog2=2&userprog3=23&userprog4=25&userprog5=25&userprog6=25&userprog7=100&userprog8=100&proceed=

如果我可以从我的应用程序中更改这些数据并使用 href 我可以做到这一点并保存一个简单的数据而无需复杂的数据连接,这是可能的吗?

<a href="mywebsite.com/simplepost?method=post&joao&6y"> << type of exeple.

但是当我使用它并按下回车键时,数据没有保存到文本文件中,为什么?

我在 php 中使用这个:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">


if ($_SERVER["REQUEST_METHOD"] == "POST") {
     
     /*Php 5.6.2  Code By : Michael S. author*/

            //globais
            $username = $_POST['usernamesave'];
            $userxp = $_POST['userxp'];
            $userid = $_POST['userid'];
}

【问题讨论】:

标签: php html save


【解决方案1】:

如果我没听错,你想保存数据使用 post 方法。如果这是您想要完成的,那么您不必在 URL 中传递变量。 这是 POST 之间的主要区别GET 方法。

现在为了数据保存,我假设你们都准备好创建一个数据库和一个表来保存你的信息,所以让我们跳到表单以及如何处理它们。

<?php
/* 
*  First form one will be the POST method.
*/

if(isset($_POST)){
 echo "post method where used from a form to send this variables";
 var_dump($_POST);
} 
?>


<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 <label for="username">Username: </label>
 <input type="text" name= "username">
 <label for="age">Age: </label>
 <input type="number" name="age"/>
 <input type="submit" value="Submit">
</form>

当您点击提交后信息将被发送并可以处理。

在get方法中不同的是,点击提交后你会看到URL中的变量,同样的方法是你可以将数据发送到其他页面。

<?php
/* 
*  Second form one will be the GET method
*  Check the url.
*/

if(isset($_GET)){
 echo "get method where made from a form with this variables";
 var_dump($_GET);
} 
?>


<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 <label for="username">Username: </label>
 <input type="text" name= "username">
 <label for="age">Age: </label>
 <input type="number" name="age"/>
 <input type="submit" value="Submit">
</form>

现在在 url 你应该看到类似的东西

example.com/index.php?username=WaredNsour&age=24

【讨论】:

    【解决方案2】:

    在处理正在发送的变量的页面代码中,尝试以下(暂时)作为测试以查看是否正在发送/看到变量。如果是,它们将被打印出来。

    <p>Post vars: 
    <?php var_dump($_POST) ?>
    </p>
    

    如果没有显示,请尝试:

    <p>Request vars: 
    <?php var_dump($_REQUEST) ?>
    </p>
    

    注意:在您发布的网址中,您有:&amp;Misael&amp; 如果 Misael 是用户名的一部分,则不应在其前面使用 &amp;。 http 将&amp;s 视为变量的分隔符。它会将Misael 视为变量名,例如:...&amp;Misael=something&amp;...。如果是空格,请使用%20

    【讨论】:

    • 然后我的源代码正常运行使用方法 post 但我的想法不是使用代码而是直接使用 url href 无需打开页面代码写入文本文件数据,我需要写入数据库,从我的 apk 来看,这与我的网站没有直接连接,那么我需要使用一个链接,该链接从应用程序发送这个页面这个 url 完整。示例:mywebsite.com/register.php 现在我的应用程序执行此操作:当用户 android 单击按钮从 android 创建帐户应用程序获取站点 url,并通过链接自动发送数据:mysite.com/register?username&id&sex 我需要在 dinamic 中执行以应用程序中的 href 方式。
    【解决方案3】:

    我相信您使用的是 GET 方法来发送信息,但在您的 PHP 代码中,您使用的是 POST 方法来获取它们。

    试试这个:

    if ($_SERVER["REQUEST_METHOD"] == "GET") {
    
     /*Php 5.6.2  Code By : Michael S. author*/
    
            //globais
            $username = $_GET['usernamesave'];
            $userxp = $_GET['userxp'];
            $userid = $_GET['userid'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      相关资源
      最近更新 更多