0

I have two php files (1.php and 2.php) linked with require

php.1 has a qr <img src="http://chart.googleapis.com/chart?chs=125x125&cht=qr&chl=<?php echo $_jattu; ?>" width="50%"> which gets its value from a string variable in 2.php $_jattu;

What I want is for <?php echo $_jattu; ?> to only echo when <a class="w3-button2 w3-black2"></a> is clicked and not when the page is loaded or refreshed, what can I do to achieve this?

3
  • can you please share your code? Commented Apr 28, 2017 at 7:20
  • Could you give an indication of what you mean by "linked with require"? Sharing your code would help. Commented Apr 28, 2017 at 7:21
  • get it running with a simple link href and condition for $_GET in PHP, then think about javascript/ajax to make it without reload. Commented Apr 28, 2017 at 7:22

2 Answers 2

1

This is imposible to do on the server side. Because the "onClick" event jumps on the client side when de user do the action.

You have few options.

  • Enable another URL for load the content of $_jattu and when the user click load it with an AJAX request. Is the best way to do it and the result is more smooth and user friendly

  • As you say you want to do it refreshing. So, slightly refresh the page with a new parameter on your url that tolds you that the "onClick" event has jump. Like:

    .../your/path?hasClick=true

And in your php code:

if(isset($_GET["hasClick"]) && $_GET["hasClick"]){
    echo $_jetty;
}

http://php.net/manual/en/reserved.variables.get.php

if you want to remember that the user has clicked "forever" you can setup a cookie.

http://php.net/manual/en/function.setcookie.php

Sign up to request clarification or add additional context in comments.

Comments

0

You can use ajax. Make a request to whatever php script you want which will return $_jattu when clicking on the link. Then update your img link in javascript using the return of the ajax request.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.