php database help easy points for you

i have a page that people go to and the user sign in adds there in to a database and set field to 0

what i want it if a user clicks the + button it adds 1 to there field if they  click the - it takes one away.

so if i click the + button 10 times it will update there field in the database to 10

can that be done ?
mikearmasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Yes.  If I understand what you want, it takes javascript and AJAX in the page and a PHP program on the server that would make the changes to your database.
0
mikearmasAuthor Commented:
ok so on the front page 2 button a + and a - when click it will run the php that will update the user clicks count up or down base off witch button he clicked.

0
Dave BaldwinFixer of ProblemsCommented:
Yes but it takes a lot of details to implement.  Somehow the PHP page has to be told what to update so the user id has to be passed to it somehow.  The AJAX on the web page sends a message to the PHP page telling it '+' or '-'.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mikearmasAuthor Commented:
well i guess i need the php part of the code. i have it connecting to the db and found the user but how to a change the click count up or down.
0
Dave BaldwinFixer of ProblemsCommented:
Show us what you have so far.
0
mikearmasAuthor Commented:

$dbuser="dbdbdb";

	  $dbpassword="dbdbdbd";

	  $database="dbdbdbd";

	  $fbid = $user_profile['id'];
	  $lastname = $user_profile['last_name'];
	  $firstname = $user_profile['first_name'];
	  $gender = $user_profile['gender'];
	  $email = $user_profile['email'];
	  $country = $user_profile['locale'];
	  //$Hometown = $user_profile['hometown']['name'];
	  $currentcity = $user_profile['location']['name'];
	  $click = "0";
	  

	  mysql_connect(localhost,$dbuser,$dbpassword);

	  @mysql_select_db($database) or die( "Unable to select database");


	  $query = "SELECT * FROM Facebook WHERE fbid ='$fbid' ";
	  $result = mysql_query($query) or die(mysql_error());


	  if (mysql_num_rows($result) )
	  {
		  	print 'user is already in table';
	     
	  }
	  else
	  {
		  
		  $add = "INSERT INTO Facebook VALUES ('','$fbid','$firstname','$lastname','$gender','$country','$currentcity','$email','$click')";
	mysql_query($add);
		   print 'user added';

	       
}





	
	$getuserclick = mysql_query($query);

	while($row = mysql_fetch_array($getuserclick)){

	echo $row["click"];

Open in new window

0
mikearmasAuthor Commented:
that is code that adds the user and displays the users click
0
Dave BaldwinFixer of ProblemsCommented:
I think this will do it.  Send it a POST with 'plus' or 'minus' and it will update the users data and return the current click count.
$dbuser="dbdbdb";
$dbpassword="dbdbdbd";
$database="dbdbdbd";

$fbid = $user_profile['id'];
mysql_connect(localhost,$dbuser,$dbpassword);
mysql_select_db($database) or die( "Unable to select database");

$updown = $_POST['plusminus'];
if($updown == 'plus') {
	$query1 = "UPDATE Facebook SET click=click+1 WHERE fbid ='$fbid' ";
	$result = mysql_query($query1) or die(mysql_error());
	}

if($updown == 'minus') {
	$query1 = "UPDATE Facebook SET click=click-1 WHERE fbid ='$fbid' ";
	$result = mysql_query($query1) or die(mysql_error());
	}
	
$query2 = "SELECT click FROM Facebook WHERE fbid ='$fbid' ";      
$getuserclick = mysql_query($query2);
while($row = mysql_fetch_array($getuserclick)){
	echo $row["click"];
	}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
The voting algorithm is shown in this article.  It is similar to what you want.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_5256-Simple-Vote-Counting-in-PHP-and-MySQL.html

You might want to consider recording all of the votes rather than just incrementing or decrementing a field.  If you have a table with all the votes, you can show trends over time.  At a minimum, you want to have separate rows for plus and minus votes.  An aggregate vote count of +3 does not tell us very much.  But a vote count of 567,244+ and 567,241- tells us that this a popular and controversial topic.
0
mikearmasAuthor Commented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.