How to click the button to increase the number of value with php?

advertisements

I'm looking for a PHP function (or "whatever works" function) that will make the value 0 go up every time my DIV is clicked and at the same time, save that new value on a PHP file.

Help me with these:
1. Click "#myDiv" to make value go up by 1
2. When "#myDiv" is clicked save new value on the PHP File (so I can execute it elsewhere)
3. Make the new saved value appear on another `DIV "#otherDiv" when "#myDiv" is clicked.

I'm doing this because I've been looking for a counter that saves the value but it doesn't work with just javascript or jquery so I hope that it can happen with PHP.

I'm willing to try any other method that works better (possibly with AJAX?)
Any help is appreciated. If you don't understand what I'm looking for, ask me questions, thanks!


Basic idea keeping it very simple: page1.php, button clicked. databased is updated. number is viewable on page2.php

demo: http://themooliecommunity.com/TEST/page1.php

Only the pages set out below are in this folder.

dbconnect.php

<?php
    $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
    if (mysqli_connect_error()) {
        die('Connect Error (' . mysqli_connect_errno() . ') '
                . mysqli_connect_error());
    }
?>

page1.php

<?php
    include 'dbconnect.php';
?>
<form method="post" action="increment.php">
   <input type="submit" Value="increment" name="increment" />
</form>

increment.php

<?php
    include 'dbconnect.php';

    $query = "UPDATE `table` SET value = value+1";
    mysqli_query($mysqli, $query);
    mysqli_close($mysqli);
    header("Location: ./page2.php");
?>

getdata.php

<?php
    include 'dbconnect.php';

    $query = "SELECT value FROM `table`";
    $data = mysqli_query($mysqli, $query);
    $row = mysqli_fetch_assoc($data);
    $number = $row['value'];
    mysqli_close($mysqli);
?>

page2.php

<?php
    include 'getdata.php';
    echo $number;
?>

SQL:

CREATE TABLE IF NOT EXISTS `table` (
  `id` int(11) NOT NULL,
  `value` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `table`
--

INSERT INTO `table` (`id`, `value`) VALUES
(0, 0);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `table`
--
ALTER TABLE `table`
  ADD PRIMARY KEY (`id`);