Code: Select all
$player_recruits = $player_recruits - 1;
$sql1 = "UPDATE `player` SET `player_recruits` = '$player_recruits' WHERE `player_id` = '$player_id' LIMIT 1";
$result1 = mysql_query($sql1) or die(mysql_error());Moderator: General Moderators
Code: Select all
$player_recruits = $player_recruits - 1;
$sql1 = "UPDATE `player` SET `player_recruits` = '$player_recruits' WHERE `player_id` = '$player_id' LIMIT 1";
$result1 = mysql_query($sql1) or die(mysql_error());Code: Select all
$sql1 = "UPDATE `player` SET `player_recruits` = `player_recruits`-1 WHERE `player_id` = '$player_id' LIMIT 1";Same results with that code.Jcart wrote:It has to be something else in your code.. but you can try a pure sql approach
Code: Select all
$sql1 = "UPDATE `player` SET `player_recruits` = `player_recruits`-1 WHERE `player_id` = '$player_id' LIMIT 1";
Code: Select all
<?php include('includes/topheader.php'); ?>
<title>Recruit - <?php echo"$htitle"; ?></title>
<meta name="description" content="" />
<?php
include('includes/dbloader.php');
include('includes/endheader.php');
include('includes/top.php');
?>
<h1>Recruit</h1>
<p>
<?php include('includes/menu.php'); ?>
<?php
if ($_SESSION['loggedin']) {
echo"
<p>You can recruit up to 50 times per day.
<br />Your percent chance to recruit increases with your level.
<br />If you get lucky, you might even recruit an already trained worker, attacker, defender, or spy.
";
$username = $_SESSION['username'];
$sql="SELECT * FROM `player` WHERE `player_name` = '$username' LIMIT 1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
$player_id = $row[player_id];
$player_level = $row[player_level];
$player_peasant = $row[player_peasant];
$player_worker = $row[player_worker];
$player_attacker = $row[player_attacker];
$player_defender = $row[player_defender];
$player_spy = $row[player_spy];
$player_recruits = $row[player_recruits];
echo"<p>You have $player_recruits recruits left today.";
if($player_recruits > 0){
$sql1 = "UPDATE `player` SET `player_recruits` = `player_recruits`-1 WHERE `player_id` = '$player_id' LIMIT 1";
$result1 = mysql_query($sql1) or die(mysql_error());Code: Select all
<?php
var_dump($player_recruits);
$player_recruits--;
var_dump($player_recruits);
?>I ran the script a few times and checked the results that show what the rest of the code on the page does.string(2) "36" int(35)
Code: Select all
<?php include 'includes/topheader.php'; ?>
<title>Recruit - <?php echo $htitle; ?></title>
<meta name="description" content="" />
<?php
include 'includes/dbloader.php';
include 'includes/endheader.php';
include 'includes/top.php';
?>
<h1>Recruit</h1>
<p>
<?php
include 'includes/menu.php';
if ($_SESSION['loggedin']) {
echo '
<p>You can recruit up to 50 times per day.
<br />Your percent chance to recruit increases with your level.
<br />If you get lucky, you might even recruit an already trained worker, attacker, defender, or spy.';
$username = $_SESSION['username'];
$sql = "SELECT *
FROM `player`
HERE `player_name` = '$username'
LIMIT 1";
$result=mysql_query($sql) or die('there was an error in the query: ' . mysql_error());
$row = mysql_fetch_array($result);
$player_id = $row['player_id'];
$player_level = $row['player_level'];
$player_peasant = $row['player_peasant'];
$player_worker = $row['player_worker'];
$player_attacker = $row['player_attacker'];
$player_defender = $row['player_defender'];
$player_spy = $row['player_spy'];
$player_recruits = intval($row['player_recruits']); // This is a number, so integerize it
echo "<p>You have $player_recruits recruits left today.";
if($player_recruits > 0){
// this is for the output messages later
$msg = '';
$msg_append = ' Recruit again...';
// This is for the screen
$player_recruits--;
// We want to lessen the player_recruits value by one in the database
$sql = "UPDATE `player`
SET `player_recruits` = `player_recruits` - 1
WHERE `player_id` = '$player_id'
LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
echo "<p>Attempting to recruit new peasants...";
$number = rand(1,100);
$chance = 35 + $player_level;
$player_peasant++;
$player_spy++;
$player_defender++;
$player_attacker++;
$player_worker++;
echo "<p>Chance: $chance";
echo "<p>Number: $number";
if ($number == 1) {
$sql = "UPDATE `player`
SET `player_worker` = '$player_worker'
WHERE `player_id` = '$player_id'
LIMIT 1";
$msg = '<p>You recruited a trained worker!';
} elseif ($number == 2) {
$sql = "UPDATE `player`
SET `player_attacker` = '$player_attacker'
WHERE `player_id` = '$player_id'
LIMIT 1";
$msg = '<p>You recruited a trained attacker!';
} elseif ($number == 3) {
$sql = "UPDATE `player`
SET `player_defender` = '$player_worker'
WHERE `player_id` = '$player_id'
LIMIT 1";
$msg = '<p>You recruited a trained defender!';
} elseif ($number == 4) {
$sql = "UPDATE `player`
SET `player_spy` = '$player_worker'
WHERE `player_id` = '$player_id'
LIMIT 1";
$msg = '<p>You recruited a trained spy!';
} elseif ($chance >= $number) {
$sql = "UPDATE `player`
SET `player_peasant` = '$player_peasant'
WHERE `player_id` = '$player_id'
LIMIT 1";
$msg = '<p>You recruited a peasant.';
} else {
$msg = '<p>No dice!';
$msg_append = ' Better luck next time...';
}
$result = mysql_query($sql) or die(mysql_error());
echo $msg . $msg_append . ' <p><a href="recruit.php">Recruit</a>';
} else {
echo '<p>Sorry, you must be logged in to continue. Visit the <a href="index.php">index</a> to login or <a href="register.php">register</a>.';
}
include 'includes/bottom.php';
include 'includes/footer.php';
?>