0

The thisvalue span is a variable that I want to save in php. This variable changes dynamically by the code js. (this is the price in the shopping cart).

How to save this value in php so that I can later add it to the query in the mysql database?

<div id="cena"><b>Razem: </b><span class="thisvalue">0.00</span>zł</div>
FSp1333
  • 55
  • 6

1 Answers1

0

Here i could suggest you to use jquery to get value of your span and then send the value to another php page with ajax.

Below i write jquery to get the span value and send using ajax.

<script>
     var val = $('.thisvalue').text();
     $.ajax({
     type: "POST",
     url: <your php file>,
     data: {value: val},
    success: success
    });
</script>

on the other hand you can get value with $_POST variable like this.

$value = $_POST['value']
saddam
  • 809
  • 8
  • 23
  • Is it possible to do it eg by the post method? for example: `
    Razem: 0.00 ...` and in php code: `$kwota2 = $_POST['kwota2'];`?
    – FSp1333 Jul 04 '18 at 11:58
  • 1
    No you can not do it because post method fetched `value` inside tags by `$_POST['tag_name']` but here span tag can not contain `value` while it contains `text`. – saddam Jul 04 '18 at 12:04
  • so, if i've already used ajax above code, how to get up this data in php? – FSp1333 Jul 04 '18 at 12:06
  • i updated it into code snnipet – saddam Jul 04 '18 at 12:11
  • you can add same file name but you have to use `isset` function so the particular php code will not execute everytime. when you use `isset` it checks for some `post` methos then its code executes. – saddam Jul 04 '18 at 12:29
  • use it like this `isset($_POST) { //code goes here to play with values }` – saddam Jul 04 '18 at 12:30
  • I can take this value in js, but I do not know how to pick it up in php. could you write it to me more easily? – FSp1333 Jul 04 '18 at 15:42
  • try updated code to send value in `data` like this `data: {value: val}` and on `php` page get it with `value` index like `$_POST['value']` – saddam Jul 04 '18 at 16:19
  • `` – FSp1333 Jul 04 '18 at 17:58
  • I write this ^ js code and the console has a good value, but I can not pick it up in php. – FSp1333 Jul 04 '18 at 17:59
  • `if (isset($_POST['value'])) { $value = $_POST['value']; echo ('lol'); }` – FSp1333 Jul 04 '18 at 18:03
  • first you have to check that if your ajax request has been sent or not to the `index.php` file. otherwise your code has not any issue. – saddam Jul 05 '18 at 09:52