Post and Get at the Same Time in PHP

Post and get at the same time in php

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

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.

How to Get and Post Method at the same time

You can’t GET and POST at the same time, they’re two different HTTP methods. You’re either making a GET request or a POST request to a URL.

If you need to scrape data from an external data source, then that’s a GET. If a user is searching on your site then that’s usually a GET too (since if the query parameters are in the URL then that can be cached, scraped by search engines etc).

In your scenario, the server-side PHP script would do a GET request to the external data feed via say, cURL and save the results to a variable; you would also query your database in this script; and then finally filter the results using the values that the user submitted.

I’m not sure where POST comes into this, unless I’ve misunderstood your problem.

POST and GET at the same time

This isnt the most beautiful code, as i just copied yours and made a few modifications.. but this form will submit back to the same page, and the php will run and insert ONLY if the form is submitted.

if(isset($_POST['answer'])) says "if the variable _POST answer is set, run the php code and insert.. if it is not set, do nothing.

You will notice the form action is left blank, you can set it to the page name yo are on.. as the form will send the variables to the same page. This is a good way of doing it because if there are errors, you can prepopulate the input or textareas with the code they just typed in.

<?php
// variables
if(isset($_POST['answer'])){
$answer=$_POST['answer'];
require ("coonection.php");
$FURL = $_POST['hi']; // there is no input name 'hi' set in your form. so this code will fail due to that.

//query
$query = "INSERT INTO `answers`(`question_id`, `answer`, `answerer`, `rate`, `dnt`) VALUES ('$FURL','$answer','ahmed','',CURRENT_TIMESTAMP)";
$data=mysql_query($query) or die(mysql_error());
if($data){
echo "Your Questions Has Been Successfully Added ";
}
}
?>

`
you will see i removed your answer_id. if you use this code, make sure that field is set to primary auto increment in your database.

<form action="" method="POST"> 
<div class="blog-post blog-single-post">
<div class="single-post-title">
<h2>Post Your Answer</h2>
</div>

<div align="Right">

<textarea class="form-control" rows="4" name="answer" id="Test"></textarea>

<br>
<div class="actions">
<button type="submit" class="btn btn-large " value="Post Answer">Post Answer</button>
</div>
</div>
</div>
</form>

NOTE: both of these snippets will go in the same page.

Post and get at the same time in php

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

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.

Can I use $_POST & $_GET at the same time?

Yes I always do that.

Also note you should never use mysql_query. Search for php PDO. Not to mention the awful @ for suppressing error

I can't use GET and POST at the same time in PHP

You can use get and post at the same time, but you shouldn't. If you want to continue to send the ID this is as simple as:

<form ...
<input type="submit" ...
<input type="hidden" name="id"
value="<?php echo htmlspecialchars($_GET['id'], ENT_QUOTES); ?>" />
</form>

Send post and get request at the same time in VOLLEY

I'm sorry i just saw something in Request.Method .

I didnt change anything in this code , only i changed Request.Method.GET to Request.Method.DEPRECATED_GET_OR_POST

I just saw this method now. So its working perfectly.



Related Topics



Leave a reply



Submit