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? Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/ 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"); Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260336 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"; Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260338 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. Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260342 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']' Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260350 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'].""); Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260357 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. Link to comment https://forums.phpfreaks.com/topic/52729-solved-automatically-adding-1/#findComment-260359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.