Reputation: 51
I know this question has been answered over a million times, but I'm very new to the whole programming scene and I just can't get it to work. Sorry, I hope you can help me!
HTML:
<div class="the_score">+76</div>
<div id="increment_value">Like</div>
I have a MySQL connection and I can fetch the data, but I want the score to update with +1 when someone clicks the Like div. I have a table "websites" with row "WebScore" that has the function int(10) (?? I hope that is correct).
I use this to fetch the data and show it on my website:
$r = rand(2,3);
$sql = "SELECT * FROM websites WHERE ID = $r";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
Upvotes: 0
Views: 2006
Reputation: 108786
I presume you have a column, not a row, called WebScore.
You need the query
UPDATE websites SET WebScore = WebScore + 1 WHERE ID = $r
As you can see, it finds the right row of your table and updates the value of the WebScore column.
This sort of things can only be done from a PHP program. It can't be done directly from a Javascript method invoked within a web browser. So, if you want to react to a user click, you'll need to post a form or invoke an Ajax style call to a php endpoint. How to do that is the province of another question.
Keep plugging away; you'll figure out this database stuff.
Upvotes: 2