0

I'm trying to create a quantiy counter that updates (+/-) in realtime using php.

<?php $q = 1; ?>
Quantity:  <button type="button" class ="button Minus" onClick="<?php $q = $q--; ?>">-</button>
<?php echo $q; ?>
<button type="button" class="button Plus" onClick="<?php $q = $q++; ?>">+</button>

It displays properly, but the onclick events are not updating the "$q" variable that is being echoed. Any tips?

  • 1
    You can't update in "realtime" with PHP (except if you use AJAX, but still why not use JS) use Javascript instead to execute code in the client side. – Spoody Dec 24 '17 at 21:00
  • 1
    Learn the difference between server side and client side. PHP runs server side and html output is sent to your browser there is no php client side. onclick attribute expects a javascript function – JoshKisb Dec 24 '17 at 21:01
  • I know the difference between clientside and serverside. My thought process was that the quantity variable would need to be sent to serverside eventually when the user chooses to submit said quantity to their cart. I do see my mistake, however with using php to initially store the variable. – TwinRayj Studios Dec 24 '17 at 22:07

0 Answers0