6 Replies - 533 Views - Last Post: 25 August 2010 - 11:20 AM

#1 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

User keeps clicking

Posted 25 August 2010 - 10:16 AM

I am using j query for a simple message box

source code :
					<script src="sections/jquery-1.3.2.min.js" language="Javascript" type="text/javascript"></script>
                      <script>
				$(document).ready(function(){					
					$("select#pokeSLOT").change(function () {
						$("button#Submit_But").text("Send " + $("select#pokeSLOT option:selected").text());
					});
					
					$("button#Submit_But").click(function () {
						var theSlot = $("select#pokeSLOT option:selected").val();
						var movePokemon = $("select#pokeSLOT option:selected").text();
						
						
						if (theSlot == "" || movePokemon == "") { alert("Required fields were left blank."); return false;}
						
						confMes = confirm("You are about to attempt to send " + movePokemon + " to your box. Are you sure?");
						if (confMes) {
							$.post("/phpDocs/phpDocs.php", {
								mode: "MovePokemon",
								pokemonName: movePokemon,
								User: "<?php echo $_SESSION['username']; ?>",
								pokeSLOT: theSlot
							

								},
							
								function(data){
									alert(data);
									location.reload(true);
										
								}
							);
							return false;
						} else {
							alert("CANCELLED");
							return false;
						}
					});




A message box pops up saying You are about to attempt to send the pokemon to your box. Are you sure? if the user keeps clicking yes it sends loads of the same pokemon to there box


My question is is there any way for it not 2 be a option and it just does it ?
so the user cant keep click yer and getting the same pokemon over and over ?

So they click the button 2 activate the j query then it just does the move pokemon
if (confMes) {
							$.post("/phpDocs/phpDocs.php", {
								mode: "MovePokemon",
								pokemonName: movePokemon,
								User: "<?php echo $_SESSION['username']; ?>",
								pokeSLOT: theSlot



Is there any way i can do this ? im into php and don;t know jquery a friend from here done this for me

This post has been edited by nick1200: 25 August 2010 - 10:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: User keeps clicking

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: User keeps clicking

Posted 25 August 2010 - 10:32 AM

on the server side I would keep a count of how many of each pokemon they have and implement a bool value to indicate whether the pokemon is inbox. Then when the user clicks yes, it changes the inbox value to true. Then you just have to write the code that you want to happen if the pokemon is inbox and what code to execute if it is not.

However you do it I would definitely recommend it be on the server side code since the user can always modify what's being sent from the browser to the server if they know how.
Was This Post Helpful? 0
  • +
  • -

#3 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: User keeps clicking

Posted 25 August 2010 - 10:37 AM

View PostNakor, on 25 August 2010 - 09:32 AM, said:

on the server side I would keep a count of how many of each pokemon they have and implement a bool value to indicate whether the pokemon is inbox. Then when the user clicks yes, it changes the inbox value to true. Then you just have to write the code that you want to happen if the pokemon is inbox and what code to execute if it is not.

However you do it I would definitely recommend it be on the server side code since the user can always modify what's being sent from the browser to the server if they know how.

The problem is the user can catch the same pokemon twice even the same level so they could have the same pokemon at the same level in there box
They could have 12 of the same pokemon at the same level

If they keep clicking yes it add the same pokemon but at level 0 so maybe i should do a if level = 0 then die on the main php fuction so it adds the main pokemon then when its about to add the clone pokemon which it don;t have a level for it will try and add the pokemon on level 0 then the if will kick in ?
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: User keeps clicking

Posted 25 August 2010 - 10:46 AM

without knowing how you have the pokemon or pokemon boxes implemented it's hard say for sure. But if each pokemon is an object then I would treat the box like an array of pokemon objects. Then it shouldn't matter what level they are. You just need to keep a running count on the number of each type of pokemon to make sure that they don't store more pokemon than they have. That might could be done with a static count that gets incremented each time the pokemon constructor is called (if you used a php class to create the pokemon) and decremented when the destructor is called.
Was This Post Helpful? 0
  • +
  • -

#5 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: User keeps clicking

Posted 25 August 2010 - 10:52 AM

View PostNakor, on 25 August 2010 - 09:46 AM, said:

without knowing how you have the pokemon or pokemon boxes implemented it's hard say for sure. But if each pokemon is an object then I would treat the box like an array of pokemon objects. Then it shouldn't matter what level they are. You just need to keep a running count on the number of each type of pokemon to make sure that they don't store more pokemon than they have. That might could be done with a static count that gets incremented each time the pokemon constructor is called (if you used a php class to create the pokemon) and decremented when the destructor is called.


well the fuction is up top and this is the sql that does all the work

	function execStorePokemon() {
			





$user = $_POST['User'];
			$slot = $_POST['pokeSLOT'];
			$pname = $_POST['pokemonName'];
			
			$qr = "SELECT t1.pokePIC,t2.pok".$slot."LV,t2.pok".$slot."EXP FROM pokemon as t1
					INNER JOIN user_pokemon as t2 ON t2.userNAME='$user'
					WHERE t1.pokeNAME='$pname' LIMIT 1";
			$rr = mysql_query($qr) or die(mysql_error());
			$vr = mysql_fetch_object($rr);
			
			$qry = "INSERT INTO user_box (username,pokemon,pokePic,time_stamp,level,exp)
					VALUES ('$user','$pname','$vr->pokePIC','$this->time','".$vr->{"pok".$slot."LV"}."','".$vr->{"pok".$slot."EXP"}."')";
			$res = mysql_query($qry) or die(mysql_error());

			if ($res) { 
				$this->execRemoveFromUser($slot,$user);
				echo "You have moved $pname to your box.";	
			
			} else {
				echo "An error occured while moving your pokemon please try again later.";
			}
		}




But now i should add


if  ( '".$vr->{"pok".$slot."LV"}."' == 0)
   die();
else






$vr->{"pok".$slot."LV

holds the level of the pokemon so is that = 0 then it will die

i am getting a blank text box after i click yes and does not move it

This post has been edited by nick1200: 25 August 2010 - 10:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: User keeps clicking

Posted 25 August 2010 - 11:15 AM

you really need a way to keep track of the count of each type of pokemon. I would suggest looking into PHP OOP and implementing some classes to do a lot of the work before you get to any database interaction.
Was This Post Helpful? 0
  • +
  • -

#7 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: User keeps clicking

Posted 25 August 2010 - 11:20 AM

I fixed it now
if any 1 else is stuck with somthing like this

i used

			if  ( $vr->{"pok".$slot."LV"} == 0)
   die();
else


just after the select

like i said up top

and works like a treat
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1