Insert GET mode

Asked

Viewed 64 times

-1

Good morning, This is the form of a question form of mine:

<form class="form-horizontal" action="chk-gerente.php?nro_pergunta=<?php  echo $nro_pergunta; ?>" method="GET">
      <fieldset>
          <legend>Pergunta <?php echo"$ordem";?>/<?php echo"$totalpergunta";?></legend>
        <div class="form-group">
          <center><h3><label><?php echo"$descpergunta";?></label></h3></center>
          <div class="col-lg-10">
            <div class="radio"><label><input type="radio" name="resp" id="optionsRadios1" value="5">OTIMO        </label></div>
            <div class="radio"><label><input type="radio" name="resp" id="optionsRadios2" value="3">REGULAR      </label></div>
            <div class="radio"><label><input type="radio" name="resp" id="optionsRadios3" value="1">RUIM         </label></div>
            <div class="radio"><label><input type="radio" name="resp" id="optionsRadios4" value="0">NAO APLICADO </label></div>
          </div>
        </div>
        <?php
         $timestamp            = @mktime(date("H")-4, date("i"),date("s"),date("m"),date("d"),date("Y"),0);
         $DataCad              = gmdate("Y-m-d", $timestamp); // Gravar $DataCad no BD
         echo"<input type='hidden' name='loja'         id='loja'         value='$loja'>";
         echo"<input type='hidden' name='id_usuario'   id='id_usuario'   value='$id_usuario'>";
         echo"<input type='hidden' name='questionario' id='questionario' value='$questionario'>";
         echo"<input type='hidden' name='area'         id='area'         value='$area'>";
         echo"<input type='hidden' name='nro_pergunta' id='nro_pergunta' value='$nro_pergunta'>";     
         echo"<input type='hidden' name='DataCad'      id='DataCad'      value='$DataCad'>";
         echo"<input type='hidden' name='pergunta'     id='pergunta'     value='$idpergunta'>";
        ?>
        <div class="form-group">
          <div class="col-lg-10 col-lg-offset-2">
            <button type="submit" class="btn btn-primary">Responder</button>
           </div>
        </div>
      </fieldset>
     </form>

How am I passing a command in the action,how could it be my input in db? I tried to do at the beginning of the page with GET more without success,?

  • You can use the value passed by parameter by the formaction to say in which the corresponding question, the action parameter, you can also collect by get.

1 answer

0


Solved. I passed as follows:

 if(isset($_GET['submit'])){
    $loja         = $_GET ["loja"];
    $id_usuario  = $_GET ["id_usuario"]; 
    $questionario = $_GET ["questionario"];
    $area         = $_GET ["area"];
    $idpergunta   = $_GET ["pergunta"];   
    $resp         = $_GET ["resp"]; 
    $datacad      = $_GET ["data_cad"]; 

  $sql_insert = mysql_query("INSERT INTO respostas 
  (resp_id,resp_loja,resp_usuario,resp_questionario,resp_area,resp_subgrupo,resp_pergunta_id,resp_resposta,resp_data,resp_status)
  VALUES 
  ('','$loja','$id_usuario','$questionario','$area','1','$idpergunta','$resp','$datacad','1')") 
   or die (mysql_error());
    mysql_query($sql_insert,$conexao); } 

Thank you.

  • 1

    Otacio, welcome to [en.so]! First, you should mark the accepted answer only if it really solves the problem. You marked the other answer as "correct" but it will only confuse people who access this question in the future, since it simply doesn’t answer the question.

  • 1

    Second, although you have solved the problem, concatenating user parameters directly into the SQL query is bad practice. I suggest you consult how to do Prepared statements. Examples can be seen here, here and here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.