Pass the $rfprod parameter by clicking on the line for a PHP program (POST Method)

Asked

Viewed 67 times

-4

<div id="posiciona">
    <table id="mostra_prod" cellpadding="1" cellspacing="3" bordercolor="#000000">
        <thead>
          <tr>
           <td align="right" bgcolor="#0a0a96">Aplicação</td>
           <td align="left"  bgcolor="#0a0a96">Referência</td> 
         </tr> 
        </thead>
        <tbody>
        <?php 
        $i=0;         
        while  ($row = mysqli_fetch_array($result_pd)) { 
            $rfprod  = $row['pro_referencia_produto'];
            $idref[] = $rfprod;  
            $i++;  
            $approd  = $row['pro_aplicacao_produto'];
            ?><tr><?php 
            echo "<td align='right' style='color: #cfcfd1; font-size:14px;'>".$approd."</td>";
            echo "<td style='color: #ffffff; font-size:11px; padding-top: 5px;'>".$rfprod."</td>";
            ?></tr><?php 
       }
       ?>   
        </tbody>      
    </table>
</div>

Tabela de Produtos

  • Your question is not very clear. Try to formulate the question better (https://answall.com/help/mcve)

  • 1

    Dear Linhares, OK! When selecting the line in the Onclick event, I need to send by POST, the item reference code to the other program in PHP, which will show all the images of this item. Grateful...!

  • But why via POST? Any particular reason? For GET it gets much simpler, see: echo "<td style='color: #ffffff; font-size:11px; padding-top: 5px;'><? php echo('<a href="PAGINA_DESTINO.php?ref='.$rfprod.'">'.$rfprod.'</a>');? ></td>

  • Leo, the command syntax is not correct! ; ? ></td> At this point in the command you are showing special characters, two red dots before the end of php’s closure. At the end of the command I entered the ; A msg error - Parse error: syntax error, Unexpected 'catalog2' (T_STRING), expecting ',' or ';' in C: wamp64 www tutorials catalog000.php on line 121

  • Leo, How will the GET command look in the catalog2.php program ?

  • Solved Leo ! echo "<td align=right style='font-size:15px'> <a href=catalog02.php? referenced=$rfprod style='color: #cfcfd1; text-Decoration: None;'>$approd</a></td>"; echo "<td style='font-size:11px; padding-top: 5px;'> <a href=catalog02.php? referent=$rfprod style='color: #ffffff; text-Decoration: None;'>$rfprod</a></td>";

Show 1 more comment

1 answer

0

If I understand correctly, you want that when the user clicks on the item, its reference code is sent by POST. Beauty. First I’ll make some modifications to your current code:

<div id="posiciona">
    <table id="mostra_prod" cellpadding="1" cellspacing="3" bordercolor="#000000">
        <thead>
          <tr>
           <td align="right" bgcolor="#0a0a96">Aplicação</td>
           <td align="left"  bgcolor="#0a0a96">Referência</td> 
         </tr> 
        </thead>
        <tbody>
        <?php 
        $i=0;         
        while  ($row = mysqli_fetch_array($result_pd)) { 
            $rfprod  = $row['pro_referencia_produto'];
            $idref[] = $rfprod;  
            $i++;  
            $approd  = $row['pro_aplicacao_produto'];
            ?><tr id="item"><?php 
            echo "<td align='right' style='color: #cfcfd1; font-size:14px;'>".$approd."</td>";
            echo "<td style='color: #ffffff; font-size:11px; padding-top: 5px;' id='referencia-item'>".$rfprod."</td>";
            ?></tr><?php 
       }
       ?>   
        </tbody>      
    </table>
</div>

What I did: I put an id on the parent "tr" so I could select it more easily, as well as on the reference "td". Now let’s go to the js part (jquery):

   $(function(){
        $("#item").click(function(){
    $.ajax({
    url: "referencia.php",
    type: post,
    data: ({referencia: $(this).find('#referencia-item').text()}),
    success: function(resposta){
    alert(resposta);
    }
    });
    });
    });

And create a file called "reference.php" Do your php on it! Example:

<?php
$referencia = $_POST['referencia'];
echo "O código de referência do produto clicado é ".$referencia;
?>

I hope you understand. Sorry for the bad formatting, I’m by phone!

  • Dear VME, I entered your code but it did not work...! When clicking on the line, there was the call to the other program...!

  • Would it be possible to send the entire code to you? I open another service record?

  • You switched to the first code, as I quoted?

  • If yes, press the line and then go to your browser console and report errors, if present

  • I changed according to your edition..! The message of the Console .... Uncaught Referenceerror: post is not defined at Htmltablerowelement.<Anonymous> (catalog00.php:135) at Htmltablerowelement.Dispatch (jquery-1.8.3.min.js:2) at Htmltablerowelement. u (jquery-1.8.3.min.js:2) Line 135 is ; url: "catalog02.php",

Browser other questions tagged

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