Like button

Ok so me and a friend have been coding a kinda posting site and we made a like button but when clicked it likes all the posts on the page… is there any way to fix this? [php]

<?php require('connection.php'); if(isset($_POST['name'] , $_POST["post"]) && $_POST['name'] != '' && $_POST['post'] != ''){ $post = mysql_real_escape_string($_POST['post']); $message = ''; $name = mysql_real_escape_string($_POST['name']); mysql_query(" INSERT INTO posts (name, post) VALUES('$name', '$post') ") or die(mysql_error()); } else { $message= 'Please enter something'; } $query = mysql_query(" SELECT * FROM posts ORDER BY posts.timestamp "); while($row = mysql_fetch_array($query)) { echo '
'; echo $row['name']; echo ' - '; echo $row['post'] ; echo ' - likes:'; echo $row['likes']; if(isset($_POST['likes'])) { $likes = $row['likes'] + 1; } ?>
<form action="wall.php" method="post">
	<input type="hidden" value="1" name="likes">
	<button type="submit">like</button>
echo '</div>';





Submit <?php

echo $message;
thanks in advance :slight_smile:

Each post should have an id in a hidden field, but where’s the code for the like section?

Irrelevant to the question but see this page here . Can you see the big warning sign that says:

Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:


You wouldn’t keep your computer without updates due to security being important. The same should apply to your websites. I can’t reiterate enough how important and integral the security of your websites should be. You can actually be fined up to £50,000 and wind up in prison in the UK for not following the Data Protection Act. Having outdated insecure databases is against the DPA.

Sponsor our Newsletter | Privacy Policy | Terms of Service