Home > Back-end >  Manually Send Data PHP method post
Manually Send Data PHP method post

Time:11-23

i'm brazilian i does a website simple to sent a simple users data, but to do a test i want sent manually newer data in a link without need complete manual form if it run then i can use directly by my app to save all users data.

see my idea:

mywebsite.com/savedata?method=post&usernamesave=Nome&Misael&userxp=34&userid=35&userlevel=31&[email protected]&userprog1=1&userprog2=2&userprog3=23&userprog4=25&userprog5=25&userprog6=25&userprog7=100&userprog8=100&proceed=

if i can change this data from my app and using hrefs i can do this and save a simple data without a complex data connection, it's possible ?

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

But when i use this and press enterkey the data isn't saved into a textfile, why ?

i using this in 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'];
}

CodePudding user response:

If i got you right you want to save data using a post method. If this is what you want to accomplish, then you don't have to pass the variables in URL. This is the main difference between POST and GET method.

Now for data saving, i will assume that you all ready created a database and a table to save your information on it, so let's jump to the form and how to handle them.

<?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>

When you click on submit the information will be sent and can be handled after.

In get method it's different you will see the variables inside the URL after hitting submit, and the same way you can send data to other pages.

<?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>

Now in the url you should see something like

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

CodePudding user response:

I believe you are using the GET method to send information but in your PHP code, you are using the POST method to fetch them.

Try this :

if ($_SERVER["REQUEST_METHOD"] == "GET") {

 /*Php 5.6.2  Code By : Michael S. author*/

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

CodePudding user response:

In the code of your page that is processing the variables being sent, try the following (temporarily) as a test to see if variables are being sent/seen. If they are, they will be printed out.

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

If nothing displays, try:

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

Note: in the url you posted you have: &Misael& if Misael is part of the username you should not use the & in front of it. http sees &s as separators for the variables. It will see Misael as a variable name, like: ...&Misael=something&.... If it is a space, use .

  • Related