Alexander Ruzhevich2016-09-09 19:43:50
Alexander Ruzhevich, 2016-09-09 19:43:50

ajax php sql form?

Good day, there is a form

<form method="post" action="search_ajax.php">

    <input type="text" class="search_input" name="search" id="search" class='search_box'/>
        <select class="search_in" name="search_in" id="search_in"> 
        <option value='' selected='selected'>Искать по</option>
        <option VALUE="id">Номер</option>
        <option VALUE='status'>Статус</option>
        <option VALUE='master'>Мастер</option> 
    <input type="submit" value="Поиск" class="search_button" /><br />


I have a form handler

if (isset($_POST['search_in']))  {
  $s_i = $_POST['search_in'];
  echo $s_i;


if (isset($_POST['search']))  {
    $s = $_POST['search'];
  echo $s;

$query_to_db = mysql_query("SELECT * FROM equipment WHERE $s_i LIKE '%$s%'");

there is ajax input fields

<script type="text/javascript">
     var search = $("#search").val();
       type: "POST",
       url: "search_ajax.php",
       data: {"search": search},
       cache: false,                                 
       success: function(response){
     return false;


and select

<script type="text/javascript">
            type : 'POST',
            url : 'search_ajax.php',
            data : { search_in: $(this).val() },
            success: function(response){



individually, they work, but if they are put together, then only select works. The question is how to pass data only together?? for example, I chose select (a search criterion) and then you enter data into input and only now that the data is transmitted.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Dmitry, 2016-09-09

Good evening.
Combine two js scripts.
Hang submit on the form
Serialize the form like this or like that
Process the data on the server
to work with the forms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question