0

I need insert data in a database and search in one input. All at once.

I used method="post" because the input with name="q" insert data in database with $_POST. But i need use $_GET + $_POST in this form.

My index.php

<form action="search.php?q=<?php echo $_GET['q']; ?>" method="post" autocomplete="off">
                            <input 
                                   required
                                   dir="ltr"
                                   name="q"
                                   class="input is-large" 
                                   type="text">
                            <p>&nbsp;</p>
                            <input type="submit" class="button is-color is-large" value="Buscar" name="go">
                        </form>

So, i am trying use $_GET['q'] to complete the form action with content of input. But not working.

I need that url stay like this: search.php?q=CONTENT OF INPUT after submit.

pme
  • 14,156
  • 3
  • 52
  • 95
  • 1
    Why don't you want to use `$_GET`? I don't understand the question. – Brad Nov 22 '18 at 02:49
  • because i need use $_POST to insert data in mysql. i need make 2 actions, post and get – Bruno R. Trocoli Nov 22 '18 at 02:51
  • Well, you can't do two actions in one request. That's impossible. You *could* do a `POST search.php?q=something` with JavaScript, but I don't follow why you'd want to. A URL like `search.php` sounds like a `GET` action to me. – Brad Nov 22 '18 at 02:52
  • 1
    This is a duplicate question please see https://stackoverflow.com/questions/2749406/post-and-get-at-the-same-time-in-php – Renzchler Nov 22 '18 at 02:58
  • You don't need two actions. URL parameters are available in $_GET even with the request uses post – Joni Nov 22 '18 at 03:27

2 Answers2

1

alternatively to Dng's answer, you can do this:

<form action="search.php" method="get" autocomplete="off">

you can have something like:

search.php?q=textbox_value_here&go=Buscar
kapitan
  • 2,008
  • 3
  • 20
  • 26
0

You don't need to use $_GET here.
You just get the value of the input has name="q" from form at search.php like $_POST["q"] then do what you want with it.

Dng
  • 121
  • 6