Bootstrap php button click event to load another page using value from the first
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
|
show 15 more comments
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
It will receive the data from the ajax request. But thewindow.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
|
show 15 more comments
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
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
javascript php mysql ajax
asked Nov 25 '18 at 15:12
Rik NamchoomRik Namchoom
115
115
It will receive the data from the ajax request. But thewindow.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
|
show 15 more comments
It will receive the data from the ajax request. But thewindow.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
|
show 15 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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