Jump to content

Recommended Posts

alright so i own a game. on part of the game you can have teams. the teams are allowed up to 20 players each. everything is function BUT when you accept a player it takes the memeber count back to 1 instead of adding to the number of memebers actually there: example; theres 19 out of 20 members, i then accept a member and it takes the member count to 1 out of 20.

 

heres the code I have:

 

<?php

include 'header.php';

$playerid = $_POST['playerid'];
$team = $_POST['team'];

$query="SELECT * FROM teams WHERE id='$team'";
$res = mysql_query($query);
$row = mysql_fetch_array($res);
if($row['memcount'] < 20){
$query="update player SET Team='$team' WHERE id='$playerid'";
$checkresult = mysql_query($query);
echo "<font size='3pt'>This player has been added</font>";
}else{
echo "<font size='4pt'>You already have 20 members!</font>";

$today = date("F j, Y, g:i a");

$sql="INSERT INTO messages (Recipient, Sender, Subject, Message, new, date)
VALUES
('$_POST[playerid]','Team Application Administration','Notification of Decline','We are sorry to inform you that you have been declined to join that team you applied for due to: too many members. No more space.','yes','$today')";
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "A message has been sent to the player telling them that they didn't get accepted. ";

exit;
}


?>     






<?php
$playerid = $_POST['playerid'];
$team = $_POST['team'];

$query="SELECT * FROM teams WHERE id='$team'";
$res = mysql_query($query);
$row = mysql_fetch_array($res);
if($row['memcount'] < 20){
$query="update teams SET memcount=('memcount'+1) WHERE id='$team'";
$checkresult = mysql_query($query);
echo "<font size='3pt'> and your memebership has increased.</font>";
}else{
echo "<font size='4pt'>Too bad.</font>";
} ?> 



     
<br><br><br>


<?php


$today = date("F j, Y, g:i a");

$sql="INSERT INTO messages (Recipient, Sender, Subject, Message, new, date)
VALUES
('$_POST[playerid]','Your Team','Notification of Acceptance','You have joined a team!','yes','$today')";
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "<font size='2pt'>A message has been sent to the player.</font>";

?>

<?php


$rid=$_POST['rid']; 

$query="DELETE FROM teamapp WHERE id='$rid'";
$checkresult = mysql_query($query);
if ($checkresult) echo '<br><br><BR>Application Deleted<BR><BR><BR>';
else echo 'update query failed';

mysql_close();
?>  

if($row['memcount'] < 20){

 

Change all instances of that to:

if($row['memcount'] < 21){

 

20 is not less than 20, so therefore the results were acting like you coded it. Change that it will update to 20, but once it goes to 21 it will hit the else.

if($row['memcount'] < 20){

 

Change all instances of that to:

if($row['memcount'] < 21){

 

20 is not less than 20, so therefore the results were acting like you coded it. Change that it will update to 20, but once it goes to 21 it will hit the else.

 

oddly enough, it is working with accepting 20 members when it is < 20 ... any clue as to why?

oddly enough, it is working with accepting 20 members when it is < 20 ... any clue as to why?

 

Nope, not unless some other part of your code does it.

 

thats really weird....I kind of want to know why its working when it shouldnt be...anyone have any ideas? :

 

<?php

include 'header.php';

$playerid = $_POST['playerid'];
$team = $_POST['team'];

$query="SELECT * FROM teams WHERE id='$team'";
$res = mysql_query($query);
$row = mysql_fetch_array($res);
if($row['memcount'] < 20){
$query="update player SET Team='$team' WHERE id='$playerid'";
$checkresult = mysql_query($query);
echo "<font size='3pt'>This player has been added</font>";
}else{
echo "<font size='4pt'>You already have 20 members!</font><BR><BR>";

$today = date("F j, Y, g:i a");

$sql="INSERT INTO messages (Recipient, Sender, Subject, Message, new, date)
VALUES
('$_POST[playerid]','Team Application Administration','Notification of Decline','We are sorry to inform you that you have been declined to join that team you applied for due to: too many members. No more space.','yes','$today')";
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "A message has been sent to the player telling them that they didn't get accepted. ";

exit;
}


?>     






<?php
$playerid = $_POST['playerid'];
$team = $_POST['team'];

$query="SELECT * FROM teams WHERE id='$team'";
$res = mysql_query($query);
$row = mysql_fetch_array($res);
if($row['memcount'] < 20){
$query="update teams SET memcount = memcount +1 WHERE id='$team'";
$checkresult = mysql_query($query);
echo "<font size='3pt'> and your memebership has increased.</font>";
}else{
echo "<font size='4pt'>Too bad.<BR><BR></font>";
} ?> 



     
<br><br><br>


<?php


$today = date("F j, Y, g:i a");

$sql="INSERT INTO messages (Recipient, Sender, Subject, Message, new, date)
VALUES
('$_POST[playerid]','Your Team','Notification of Acceptance','You have joined a team!','yes','$today')";
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "<font size='2pt'>A message has been sent to the player.</font>";

?>

<?php


$rid=$_POST['rid']; 

$query="DELETE FROM teamapp WHERE id='$rid'";
$checkresult = mysql_query($query);
if ($checkresult) echo '<br><br><BR>Application Deleted<BR><BR><BR>';
else echo 'update query failed';

mysql_close();
?>  

Actually, it is perfectly normal.  You have "$row['memcount'] < 20" twice in your code.  The first one determines if the player's team should be changed, the second one updates the counter.  So, for example:

 

The count is 19.  A player wants to choose this team.

 

count < 20: ok, player's team is changed.

count < 20: ok, increase counter from 19 to 20.

 

Next player tries:

 

count < 20: not ok it is 20 now, maximum number of players reached.

 

This works because the counter is increased only after you change the team.

Actually, it is perfectly normal.  You have "$row['memcount'] < 20" twice in your code.  The first one determines if the player's team should be changed, the second one updates the counter.  So, for example:

 

The count is 19.  A player wants to choose this team.

 

count < 20: ok, player's team is changed.

count < 20: ok, increase counter from 19 to 20.

 

Next player tries:

 

count < 20: not ok it is 20 now, maximum number of players reached.

 

This works because the counter is increased only after you change the team.

 

thank you :) i was pretty baffled for a second!

 

you guys are amazing <3

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.