cheechm Posted May 23, 2007 Share Posted May 23, 2007 Hi, I have created a database for a house points system. Everything is working fine, but there is one thing I can't do. I want to be able to click a link, and for the person to have 1 point added to them. It goes like this so far: $result = mysql_query("SELECT * FROM points"); while($row = mysql_fetch_array($result)) { $link = 'addpoints.php?firstname=' . $row['FirstName'] . '&lastname=' . $row['LastName'] . '&Points=' . $row['Points']; echo "<a href='".$link."'>+points</a>"; echo $row['FirstName'] . " " . $row['LastName'] ." ". $row['Tutor'] . " " . $row['Points']; The only thing I can't do, is add 1 point to the current amount of points. How would I do that? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 23, 2007 Share Posted May 23, 2007 Not exactly sure how you have things set up...but I would assume sosmething like this: mysql_query("UPDATE points SET points=points+1"); Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 23, 2007 Author Share Posted May 23, 2007 This is the add points file: mysql_select_db("b7_463487_LPS", $con); mysql_query("UPDATE points SET Points = '$_GET[Points=points+1]' WHERE FirstName = '$_GET[firstname]' AND LastName = '$_GET[lastname]'"); echo "$_GET[firstname] now has $_GET[Points] points"; Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2007 Share Posted May 23, 2007 in "addpoints.php" <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; mysql_query("UPDATE points SET points=points+1 WHERE firstname='$firstname' AND lastname='$lastname'"); ?> It would better to use a record id instead of firstname/lastname just in case you get 2 people with same name, plus it's more efficient. Quote Link to comment Share on other sites More sharing options...
cheechm Posted May 23, 2007 Author Share Posted May 23, 2007 I know for sure that I won't get more than one, but for future reference, would I just put mysql_query("UPDATE points SET points=points+1 WHERE id='$_GET['id']' Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 23, 2007 Share Posted May 23, 2007 Like this: mysql_query("UPDATE points SET points=points+1 WHERE id=".$_GET['id'].""); Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2007 Share Posted May 23, 2007 and change the link to $link = 'addpoints.php?id=' . $row['id']; Also, google "sql injection" to check out the dangers of using GET,POST,COOKIE data in queries. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.