1

I'm beginner of php and javascript so i dont really now whats the wrong in my code. i just want to send a javascript variable to php and its not working, i dont now why. These files all different pages. So its a click function in javascript:

file: SelectTableRow.js.

var productTable = document.getElementById('ProductTable'), rIndexB;

for(var i = 0; i < productTable.rows.length; i++)
{
    productTable.rows[i].onclick = function()
    {
        rIndex = this.rowsIndexB;
        var bAzon = this.cells[0].innerHTML;

        $.post("AddProductTable.php", {BAzon: bAzon}, function(){
        $('#load').load('AddProductTable.php');
        });

        console.log(bAzon);
    }
}

The database is running clear too. The data what should display:

file: AddProductTable.php

<table class="DataTable">
    <th>Azonosito</th>
    <th>Név</th>
    <th>Mennyiség</th>
    <th>Mértékegység</th>
    <th>Ár</th>
    <th>Törlés</th>


<?php

require_once 'Connect.php'; // its 100% working.

$BAzon = $_POST['BAzon'];  // 0 result :(

if($result = $link_database->query("SELECT bevetAzon, termekAzon, bevettMennyiseg, bevettAr FROM bevetttermek WHERE bevetAzon = '$BAzon'"))
{
    $table = $result->fetch_all();

    foreach($table as $row)
    {   
            echo "<tr>";
            foreach($row as $record)
            {   
                echo "<td>".$record."</td>";
            }
            echo "</tr>";
    }
}

echo "BAZON: ".$BAzon;  //0 result
echo "POST: ".$_POST['BAzon'];  // 0 result

?>
</table>

and the file where i call this(just the important part):

Index.php

<div id="load">

</div>

When im trying a test number, its working, display the datas. Please help me, i cant go through this one.

6
  • 1
    open developer tools in your browser, open the Network tab and see that request once it's made - you can see what POST data is being sent to AddProductTable Commented Feb 5, 2019 at 14:32
  • 1
    Ohh, thanks, thats shows me, the datas are send. And its sent, but why i cant display? :( <table class="DataTable"> <th>Azonosito</th> <th>Név</th> <th>Mennyiség</th> <th>Mértékegység</th> <th>Ár</th> <th>Törlés</th> <tr><td>98</td><td>4</td><td>10</td><td>10</td></tr><tr><td>98</td><td>4</td><td>10</td><td>10</td></tr><tr><td>98</td><td>4</td><td>10</td><td>10</td></tr><tr><td>98</td><td>4</td><td>10</td><td>10</td></tr><tr><td>98</td><td>1</td><td>10</td><td>10</td></tr>BAZON: 98POST: 98 Commented Feb 5, 2019 at 14:38
  • what's the names of the POST fields? Commented Feb 5, 2019 at 14:42
  • $BAzon = $_POST['BAzon']; or what kinda of fields? :D Commented Feb 5, 2019 at 14:48
  • In your code you post your data to AddProductTable.php, but in the next line you get a completely fresh AddProductTable.php with no data posted. (I hope this explanation makes sense) I think you will find your answer here: stackoverflow.com/questions/1562043/… Commented Feb 5, 2019 at 14:56

1 Answer 1

1

So this should do the trick:

var productTable = document.getElementById('ProductTable'), rIndexB;

for(var i = 0; i < productTable.rows.length; i++)
{
    productTable.rows[i].onclick = function()
    {
        rIndex = this.rowsIndexB;
        var bAzon = this.cells[0].innerHTML;

        $.post("AddProductTable.php", {BAzon: bAzon}, function(data){
        $('#load').html(data);
        });

        console.log(bAzon);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.