Bootstrap php button click event to load another page using value from the first












0















The codes first:



transactions.php



<tbody>

<?php
include 'database_connection.php';
$sql = "SELECT `id`, `date`, `name`, `phone`, `subtotal`, `status` FROM `sales`";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>
<tr>
<td><?php echo $row['date']; ?></td>
<td> <?php echo $row['id'] ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['subtotal']; ?></td>
<td><?php echo $row['status']; ?>
<td><button type="button" class="btn btn-success btn-xs" id="<?php echo $row['id'];?>" onclick='view(this.id)'>View / Print</button>
</tr>
<?php endwhile; ?>
</tbody>
</table>

<script>

<script>
function view(id){


$.ajax({
url: "invoice_view",
type:"post",
data:{ val : id },


success: function(result){

window.open ("invoice_view.php","mywindow");

}
});
}
</script>


invoice_view.php



<?php
include 'database_connection.php';
$data=$_POST['val'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>


So I am trying to pass the id of that specific transaction to the invoice_view.php page so it loads that specific transaction.



The screenshot of the transactions.php page is: http://oi65.tinypic.com/2ngh24l.jpg



Please help me figure out where am I doing wrong? The invoice_view isn't even receiving the value I'm sending from the transactions page.










share|improve this question























  • It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

    – charlietfl
    Nov 25 '18 at 15:18













  • how do i fix that?

    – Rik Namchoom
    Nov 25 '18 at 15:19











  • Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

    – charlietfl
    Nov 25 '18 at 15:20













  • I am not sure how to do that ?

    – Rik Namchoom
    Nov 25 '18 at 15:26











  • Do what? Both issues easy to research

    – charlietfl
    Nov 25 '18 at 15:28


















0















The codes first:



transactions.php



<tbody>

<?php
include 'database_connection.php';
$sql = "SELECT `id`, `date`, `name`, `phone`, `subtotal`, `status` FROM `sales`";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>
<tr>
<td><?php echo $row['date']; ?></td>
<td> <?php echo $row['id'] ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['subtotal']; ?></td>
<td><?php echo $row['status']; ?>
<td><button type="button" class="btn btn-success btn-xs" id="<?php echo $row['id'];?>" onclick='view(this.id)'>View / Print</button>
</tr>
<?php endwhile; ?>
</tbody>
</table>

<script>

<script>
function view(id){


$.ajax({
url: "invoice_view",
type:"post",
data:{ val : id },


success: function(result){

window.open ("invoice_view.php","mywindow");

}
});
}
</script>


invoice_view.php



<?php
include 'database_connection.php';
$data=$_POST['val'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>


So I am trying to pass the id of that specific transaction to the invoice_view.php page so it loads that specific transaction.



The screenshot of the transactions.php page is: http://oi65.tinypic.com/2ngh24l.jpg



Please help me figure out where am I doing wrong? The invoice_view isn't even receiving the value I'm sending from the transactions page.










share|improve this question























  • It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

    – charlietfl
    Nov 25 '18 at 15:18













  • how do i fix that?

    – Rik Namchoom
    Nov 25 '18 at 15:19











  • Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

    – charlietfl
    Nov 25 '18 at 15:20













  • I am not sure how to do that ?

    – Rik Namchoom
    Nov 25 '18 at 15:26











  • Do what? Both issues easy to research

    – charlietfl
    Nov 25 '18 at 15:28
















0












0








0








The codes first:



transactions.php



<tbody>

<?php
include 'database_connection.php';
$sql = "SELECT `id`, `date`, `name`, `phone`, `subtotal`, `status` FROM `sales`";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>
<tr>
<td><?php echo $row['date']; ?></td>
<td> <?php echo $row['id'] ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['subtotal']; ?></td>
<td><?php echo $row['status']; ?>
<td><button type="button" class="btn btn-success btn-xs" id="<?php echo $row['id'];?>" onclick='view(this.id)'>View / Print</button>
</tr>
<?php endwhile; ?>
</tbody>
</table>

<script>

<script>
function view(id){


$.ajax({
url: "invoice_view",
type:"post",
data:{ val : id },


success: function(result){

window.open ("invoice_view.php","mywindow");

}
});
}
</script>


invoice_view.php



<?php
include 'database_connection.php';
$data=$_POST['val'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>


So I am trying to pass the id of that specific transaction to the invoice_view.php page so it loads that specific transaction.



The screenshot of the transactions.php page is: http://oi65.tinypic.com/2ngh24l.jpg



Please help me figure out where am I doing wrong? The invoice_view isn't even receiving the value I'm sending from the transactions page.










share|improve this question














The codes first:



transactions.php



<tbody>

<?php
include 'database_connection.php';
$sql = "SELECT `id`, `date`, `name`, `phone`, `subtotal`, `status` FROM `sales`";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>
<tr>
<td><?php echo $row['date']; ?></td>
<td> <?php echo $row['id'] ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['subtotal']; ?></td>
<td><?php echo $row['status']; ?>
<td><button type="button" class="btn btn-success btn-xs" id="<?php echo $row['id'];?>" onclick='view(this.id)'>View / Print</button>
</tr>
<?php endwhile; ?>
</tbody>
</table>

<script>

<script>
function view(id){


$.ajax({
url: "invoice_view",
type:"post",
data:{ val : id },


success: function(result){

window.open ("invoice_view.php","mywindow");

}
});
}
</script>


invoice_view.php



<?php
include 'database_connection.php';
$data=$_POST['val'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);

while ($row = mysqli_fetch_array($result)):
?>


So I am trying to pass the id of that specific transaction to the invoice_view.php page so it loads that specific transaction.



The screenshot of the transactions.php page is: http://oi65.tinypic.com/2ngh24l.jpg



Please help me figure out where am I doing wrong? The invoice_view isn't even receiving the value I'm sending from the transactions page.







javascript php mysql ajax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 15:12









Rik NamchoomRik Namchoom

115




115













  • It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

    – charlietfl
    Nov 25 '18 at 15:18













  • how do i fix that?

    – Rik Namchoom
    Nov 25 '18 at 15:19











  • Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

    – charlietfl
    Nov 25 '18 at 15:20













  • I am not sure how to do that ?

    – Rik Namchoom
    Nov 25 '18 at 15:26











  • Do what? Both issues easy to research

    – charlietfl
    Nov 25 '18 at 15:28





















  • It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

    – charlietfl
    Nov 25 '18 at 15:18













  • how do i fix that?

    – Rik Namchoom
    Nov 25 '18 at 15:19











  • Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

    – charlietfl
    Nov 25 '18 at 15:20













  • I am not sure how to do that ?

    – Rik Namchoom
    Nov 25 '18 at 15:26











  • Do what? Both issues easy to research

    – charlietfl
    Nov 25 '18 at 15:28



















It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

– charlietfl
Nov 25 '18 at 15:18







It will receive the data from the ajax request. But the window.open will run a new instance of the php script and will have no post data

– charlietfl
Nov 25 '18 at 15:18















how do i fix that?

– Rik Namchoom
Nov 25 '18 at 15:19





how do i fix that?

– Rik Namchoom
Nov 25 '18 at 15:19













Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

– charlietfl
Nov 25 '18 at 15:20







Must it be a post? A GET would let you just use an <a> link and pass id in the url and not require any javascript. Note you are open to sql injection by not parameterizing your queries with either post or get

– charlietfl
Nov 25 '18 at 15:20















I am not sure how to do that ?

– Rik Namchoom
Nov 25 '18 at 15:26





I am not sure how to do that ?

– Rik Namchoom
Nov 25 '18 at 15:26













Do what? Both issues easy to research

– charlietfl
Nov 25 '18 at 15:28







Do what? Both issues easy to research

– charlietfl
Nov 25 '18 at 15:28














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468866%2fbootstrap-php-button-click-event-to-load-another-page-using-value-from-the-first%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468866%2fbootstrap-php-button-click-event-to-load-another-page-using-value-from-the-first%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin