How to check button is clicked or not in PHP?












1















I have searched for this issue but all solution in javaScript related. I need to check a button is clicked or not. Button (<a href="something"></a>) is also link to other page. I have tried but my code is working for when anyone view that page. I want when anyone click on view button. My Code:



 $for_linking = preg_replace(array('/.[A-Z]*/i') , '', $orders->order_file);

if (isset($_GET['link'])) {
$link = $_GET['link'];
if($_SERVER['PHP_SELF'] == $for_linking){
$ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);
}
}

return '<a href="' . url("file").'/'.$orders->order_file.'/?link='.$for_linking.'" class="btn btn-xs btn-primary">View</a>';


I have used datatable to show the data. If i don't use if condition then data is inserting when i page viewed. But i want when anyone click on View then data will be inserted. So i can i use if condition here?



Below Code is work for just view page:



    $ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);

return '<a href="' . url("file").'/'.$orders->order_file.'" class="btn btn-xs btn-primary">View</a>';


Table:



enter image description here










share|improve this question

























  • so why you don't use ajax?

    – m.elewa
    Dec 31 '18 at 8:12











  • @m.elewa i didn't with ajax much.

    – Chonchol Mahmud
    Dec 31 '18 at 8:15






  • 2





    I really don't get what you want to achieve, could you please elaborate this a bit clearer?

    – maio290
    Dec 31 '18 at 8:21











  • Ajax would be your best option.

    – Joseph_J
    Dec 31 '18 at 8:22











  • @maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

    – Chonchol Mahmud
    Dec 31 '18 at 8:32


















1















I have searched for this issue but all solution in javaScript related. I need to check a button is clicked or not. Button (<a href="something"></a>) is also link to other page. I have tried but my code is working for when anyone view that page. I want when anyone click on view button. My Code:



 $for_linking = preg_replace(array('/.[A-Z]*/i') , '', $orders->order_file);

if (isset($_GET['link'])) {
$link = $_GET['link'];
if($_SERVER['PHP_SELF'] == $for_linking){
$ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);
}
}

return '<a href="' . url("file").'/'.$orders->order_file.'/?link='.$for_linking.'" class="btn btn-xs btn-primary">View</a>';


I have used datatable to show the data. If i don't use if condition then data is inserting when i page viewed. But i want when anyone click on View then data will be inserted. So i can i use if condition here?



Below Code is work for just view page:



    $ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);

return '<a href="' . url("file").'/'.$orders->order_file.'" class="btn btn-xs btn-primary">View</a>';


Table:



enter image description here










share|improve this question

























  • so why you don't use ajax?

    – m.elewa
    Dec 31 '18 at 8:12











  • @m.elewa i didn't with ajax much.

    – Chonchol Mahmud
    Dec 31 '18 at 8:15






  • 2





    I really don't get what you want to achieve, could you please elaborate this a bit clearer?

    – maio290
    Dec 31 '18 at 8:21











  • Ajax would be your best option.

    – Joseph_J
    Dec 31 '18 at 8:22











  • @maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

    – Chonchol Mahmud
    Dec 31 '18 at 8:32
















1












1








1








I have searched for this issue but all solution in javaScript related. I need to check a button is clicked or not. Button (<a href="something"></a>) is also link to other page. I have tried but my code is working for when anyone view that page. I want when anyone click on view button. My Code:



 $for_linking = preg_replace(array('/.[A-Z]*/i') , '', $orders->order_file);

if (isset($_GET['link'])) {
$link = $_GET['link'];
if($_SERVER['PHP_SELF'] == $for_linking){
$ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);
}
}

return '<a href="' . url("file").'/'.$orders->order_file.'/?link='.$for_linking.'" class="btn btn-xs btn-primary">View</a>';


I have used datatable to show the data. If i don't use if condition then data is inserting when i page viewed. But i want when anyone click on View then data will be inserted. So i can i use if condition here?



Below Code is work for just view page:



    $ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);

return '<a href="' . url("file").'/'.$orders->order_file.'" class="btn btn-xs btn-primary">View</a>';


Table:



enter image description here










share|improve this question
















I have searched for this issue but all solution in javaScript related. I need to check a button is clicked or not. Button (<a href="something"></a>) is also link to other page. I have tried but my code is working for when anyone view that page. I want when anyone click on view button. My Code:



 $for_linking = preg_replace(array('/.[A-Z]*/i') , '', $orders->order_file);

if (isset($_GET['link'])) {
$link = $_GET['link'];
if($_SERVER['PHP_SELF'] == $for_linking){
$ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);
}
}

return '<a href="' . url("file").'/'.$orders->order_file.'/?link='.$for_linking.'" class="btn btn-xs btn-primary">View</a>';


I have used datatable to show the data. If i don't use if condition then data is inserting when i page viewed. But i want when anyone click on View then data will be inserted. So i can i use if condition here?



Below Code is work for just view page:



    $ip_address = gethostbyname(trim(`hostname`));
$pc_username = getenv("username");

DB::table('click_counts')->insertGetId([
'ip' => $ip_address,
'username' => $pc_username,
'order_id' => $orders->id,
]);

return '<a href="' . url("file").'/'.$orders->order_file.'" class="btn btn-xs btn-primary">View</a>';


Table:



enter image description here







php laravel datatable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 8:46







Chonchol Mahmud

















asked Dec 31 '18 at 8:02









Chonchol MahmudChonchol Mahmud

1,91511441




1,91511441













  • so why you don't use ajax?

    – m.elewa
    Dec 31 '18 at 8:12











  • @m.elewa i didn't with ajax much.

    – Chonchol Mahmud
    Dec 31 '18 at 8:15






  • 2





    I really don't get what you want to achieve, could you please elaborate this a bit clearer?

    – maio290
    Dec 31 '18 at 8:21











  • Ajax would be your best option.

    – Joseph_J
    Dec 31 '18 at 8:22











  • @maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

    – Chonchol Mahmud
    Dec 31 '18 at 8:32





















  • so why you don't use ajax?

    – m.elewa
    Dec 31 '18 at 8:12











  • @m.elewa i didn't with ajax much.

    – Chonchol Mahmud
    Dec 31 '18 at 8:15






  • 2





    I really don't get what you want to achieve, could you please elaborate this a bit clearer?

    – maio290
    Dec 31 '18 at 8:21











  • Ajax would be your best option.

    – Joseph_J
    Dec 31 '18 at 8:22











  • @maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

    – Chonchol Mahmud
    Dec 31 '18 at 8:32



















so why you don't use ajax?

– m.elewa
Dec 31 '18 at 8:12





so why you don't use ajax?

– m.elewa
Dec 31 '18 at 8:12













@m.elewa i didn't with ajax much.

– Chonchol Mahmud
Dec 31 '18 at 8:15





@m.elewa i didn't with ajax much.

– Chonchol Mahmud
Dec 31 '18 at 8:15




2




2





I really don't get what you want to achieve, could you please elaborate this a bit clearer?

– maio290
Dec 31 '18 at 8:21





I really don't get what you want to achieve, could you please elaborate this a bit clearer?

– maio290
Dec 31 '18 at 8:21













Ajax would be your best option.

– Joseph_J
Dec 31 '18 at 8:22





Ajax would be your best option.

– Joseph_J
Dec 31 '18 at 8:22













@maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

– Chonchol Mahmud
Dec 31 '18 at 8:32







@maio290 i want to insert some data(ip & pc username) into database when anyone click on view button(Look at the table picture).

– Chonchol Mahmud
Dec 31 '18 at 8:32














1 Answer
1






active

oldest

votes


















0














You could use a parameter on the button



<a href="something?action=send&id=XX"></a>


In php script on page something, you use $_GET for the action.



$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'send') {
// the send buttons was clicked
$id = $_GET['id'];
}





share|improve this answer


























  • Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

    – Chonchol Mahmud
    Dec 31 '18 at 9:46











  • Ok you want a popup on the same page?

    – Henry
    Dec 31 '18 at 9:49











  • No. The view button will redirect other page.

    – Chonchol Mahmud
    Dec 31 '18 at 9:55











  • I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

    – Henry
    Dec 31 '18 at 10:00











  • previous code wasn't working.

    – Chonchol Mahmud
    Dec 31 '18 at 10:03











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%2f53985051%2fhow-to-check-button-is-clicked-or-not-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You could use a parameter on the button



<a href="something?action=send&id=XX"></a>


In php script on page something, you use $_GET for the action.



$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'send') {
// the send buttons was clicked
$id = $_GET['id'];
}





share|improve this answer


























  • Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

    – Chonchol Mahmud
    Dec 31 '18 at 9:46











  • Ok you want a popup on the same page?

    – Henry
    Dec 31 '18 at 9:49











  • No. The view button will redirect other page.

    – Chonchol Mahmud
    Dec 31 '18 at 9:55











  • I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

    – Henry
    Dec 31 '18 at 10:00











  • previous code wasn't working.

    – Chonchol Mahmud
    Dec 31 '18 at 10:03
















0














You could use a parameter on the button



<a href="something?action=send&id=XX"></a>


In php script on page something, you use $_GET for the action.



$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'send') {
// the send buttons was clicked
$id = $_GET['id'];
}





share|improve this answer


























  • Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

    – Chonchol Mahmud
    Dec 31 '18 at 9:46











  • Ok you want a popup on the same page?

    – Henry
    Dec 31 '18 at 9:49











  • No. The view button will redirect other page.

    – Chonchol Mahmud
    Dec 31 '18 at 9:55











  • I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

    – Henry
    Dec 31 '18 at 10:00











  • previous code wasn't working.

    – Chonchol Mahmud
    Dec 31 '18 at 10:03














0












0








0







You could use a parameter on the button



<a href="something?action=send&id=XX"></a>


In php script on page something, you use $_GET for the action.



$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'send') {
// the send buttons was clicked
$id = $_GET['id'];
}





share|improve this answer















You could use a parameter on the button



<a href="something?action=send&id=XX"></a>


In php script on page something, you use $_GET for the action.



$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'send') {
// the send buttons was clicked
$id = $_GET['id'];
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 31 '18 at 9:59

























answered Dec 31 '18 at 9:29









HenryHenry

19517




19517













  • Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

    – Chonchol Mahmud
    Dec 31 '18 at 9:46











  • Ok you want a popup on the same page?

    – Henry
    Dec 31 '18 at 9:49











  • No. The view button will redirect other page.

    – Chonchol Mahmud
    Dec 31 '18 at 9:55











  • I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

    – Henry
    Dec 31 '18 at 10:00











  • previous code wasn't working.

    – Chonchol Mahmud
    Dec 31 '18 at 10:03



















  • Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

    – Chonchol Mahmud
    Dec 31 '18 at 9:46











  • Ok you want a popup on the same page?

    – Henry
    Dec 31 '18 at 9:49











  • No. The view button will redirect other page.

    – Chonchol Mahmud
    Dec 31 '18 at 9:55











  • I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

    – Henry
    Dec 31 '18 at 10:00











  • previous code wasn't working.

    – Chonchol Mahmud
    Dec 31 '18 at 10:03

















Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

– Chonchol Mahmud
Dec 31 '18 at 9:46





Henry, i have tried this way, but it doesn't work for me. I want this kind of solution.

– Chonchol Mahmud
Dec 31 '18 at 9:46













Ok you want a popup on the same page?

– Henry
Dec 31 '18 at 9:49





Ok you want a popup on the same page?

– Henry
Dec 31 '18 at 9:49













No. The view button will redirect other page.

– Chonchol Mahmud
Dec 31 '18 at 9:55





No. The view button will redirect other page.

– Chonchol Mahmud
Dec 31 '18 at 9:55













I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

– Henry
Dec 31 '18 at 10:00





I edited the answer, if you ad an unique id tot each link, you will be able to tell wich button was clicked.

– Henry
Dec 31 '18 at 10:00













previous code wasn't working.

– Chonchol Mahmud
Dec 31 '18 at 10:03





previous code wasn't working.

– Chonchol Mahmud
Dec 31 '18 at 10:03


















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%2f53985051%2fhow-to-check-button-is-clicked-or-not-in-php%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

Mossoró

Cannot access a disposed object : DataContext

Can't read property showImagePicker of undefined in react native iOS