0

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:

<?php
  include_once("connect.php");
  include_once("rate.php");

  $con=mysqli_connect("10.168.1.49","danielaf_adam","adamchip22","danielaf_adam");

  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.

Edited by adamchippy

3
Contributors
5
Replies
36
Views
3 Years
Discussion Span
Last Post by GliderPilot
0

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

0

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.

0

$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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.