Hey there. I'm building a project in PHP/MySQL and it is a sort of FaceMash project. I am able to call the images (with image name and points) from the database. I have managed to use the MySQL Update query in order to increase the points that each image gets when clicked but it just applies this to every image in the database. I cannot work out how to use the WHERE part of the update query that gives the point to that specific image that was clicked.

I have it set up as follows:

rate.php (the main page) *Click on an image* --> update.php (Which contains the update query) 

The query I currently have is:



  mysqli_query($con,"UPDATE teachers SET points= points+1 WHERE row='$row'");


Some help would be really appreciated as I have been pondering on this one for ages. Cheers.

Recommended Answers

All 5 Replies

Where are you defining the $row variable? And what is it defined as? Also, what data type is the row attribute in the table

It is in my main rate.php file:

while($row = mysql_fetch_array($result))
  echo $row['name'] . "<br /><br />";
  echo '<a href="update.php">' . $row['image'] . '</a><br /><br />';
  echo '<button class="btn btn-success">&nbsp;<span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;' . $row['points'] . '&nbsp;pnts</button>';

Not sure what you mean by the last bit.

$row is an array that contains your data that was retrieved from the DB, it is not a column in your table and it's not passed to update.php. You need to change your link so that it passes a unique identifier (The table row's Unique Key, possibly ID). Than when you do your update statement you can use that to only update the one row.

So the link would be something like this - update.php?id=7 ??

that's correct, than you get use the $_GET['id] to retreive that number in your update script

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.