Jump to content

[SOLVED] UPDATE Problem - inputting integers separated by comma's


MasterACE14

Recommended Posts

Morning Everyone,

 

I have a script which is suppose to UPDATE a user in the database depending on which button they pressed on the previous page. But it doesn't seem to be running the UPDATE query at all.

 

here's my script.

<?php // armory

player_session();

/**********************/
// Player Select Variables //
/**********************/

// User Information
$player_accountid = player_table("id");
$player_username = player_table("username");

// money
$player_money = player_table("money");

// Inventory
$player_weaponid = player_table("weaponid");
$player_armorid = player_table("armorid");
$player_vehicleid = player_table("vehicleid");
$player_weapons = player_table("weapons");
$player_armors = player_table("armors");
$player_vehicles = player_table("vehicles");

// Equipped Items

// Names
$equippedweaponname = select_array($weapons,$player_weaponid,"weapon");
$equippedarmorname = select_array($armors,$player_armorid,"armor");
$equippedvehiclename = select_array($vehicles,$player_vehicleid,"vehicle");

// ID
$equippedweaponid = select_array($weapons,$player_weaponid,"id");
$equippedarmorid = select_array($armors,$player_armorid,"id");
$equippedvehicleid = select_array($vehicles,$player_vehicleid,"id");


// Purchase Weapon $_POST's
$item_bought = addslashes($_POST["buy"]);
$item_price = addslashes($_POST["itemprice"]);
$item_type = addslashes($_POST["itemtype"]);
$item_id = addslashes($_POST["itemid"]);

/*
database connection has been made on the page included before this one.
*/

?>

<div id = "base">
<center><b><u>Armory</u></b><br></center><br>

<!-- Left Column -->
<div id = "leftcolumn">

<div id = "inventory_items">

<?php

if($player_money < $item_price) 
{ die("<b>You do not have enough money!</b>"); }

else {

  // current money - weapon price = your new money
  $new_money = $player_money - $item_price;
    
  // run the queries for you - insert your new amount of money
  $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error());
  
// check if it is a weapon, armor, or vehicle
if($item_type == 'weapon') { 
   $type = 'weapons'; 
}elseif ($item_type == 'armor') { 
   $type = 'armors'; 
}elseif ($item_type == 'vehicle') { 
   $type = 'vehicles'; 
}
  
  // run the queries for you - give you your weapon
  $typex = $type . ',' . $item_id;
  $update = "UPDATE `cf_users` SET `$type` = '$typex' WHERE `id`='" . $player_accountid . "' LIMIT 1";

  $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error());

?>

	<?php /* Grab weapon Array and Display it */

foreach ($weapons as $key => $val)
{	
if($item_bought == $val[$item_id]){
		echo '<table class="fix"><tr>';
		if($item_bought == "weapons"){
			$x= 'weapon';
		}
		elseif($item_bought == "armors"){
			$x= 'armor';
		}
		elseif($item_bought == "vehicles"){
			$x= 'vehicle';
		}
		echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		if($item_bought == "weapons"){
			$y= 'damage';
		}
		elseif($item_bought == "armors"){
			$y= 'defence';
		}
		elseif($item_bought == "vehicles"){
			$y= 'power';
		}
		echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>';
		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>';
		echo '</table><br />';
}

    }

	?>


	<?php /* Grab weapon Array and Display it */

foreach ($armors as $key => $val)
{	
if($item_bought == $val[$item_id]){
		echo '<table class="fix"><tr>';
		if($item_bought == "weapons"){
			$x= 'weapon';
		}
		elseif($item_bought == "armors"){
			$x= 'armor';
		}
		elseif($item_bought == "vehicles"){
			$x= 'vehicle';
		}
		echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		if($item_bought == "weapons"){
			$y= 'damage';
		}
		elseif($item_bought == "armors"){
			$y= 'defence';
		}
		elseif($item_bought == "vehicles"){
			$y= 'power';
		}
		echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>';
		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>';
		echo '</table><br />';
}

    }

	?>

	<?php /* Grab weapon Array and Display it */

foreach ($vehicles as $key => $val)
{	
if($item_bought == $val[$item_id]){
		echo '<table class="fix"><tr>';
		if($item_bought == "weapons"){
			$x= 'weapon';
		}
		elseif($item_bought == "armors"){
			$x= 'armor';
		}
		elseif($item_bought == "vehicles"){
			$x= 'vehicle';
		}
		echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		if($item_bought == "weapons"){
			$y= 'damage';
		}
		elseif($item_bought == "armors"){
			$y= 'defence';
		}
		elseif($item_bought == "vehicles"){
			$y= 'power';
		}
		echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>';
		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>';
		echo '</table><br />';
}

    }

} // end the 'else' statement
	?>

</div>

</div>


<!-- Right Column -->
<div id = "rightcolumn">



</div>

 

Any help is greatly appreciated.

 

Regards ACE

Link to comment
Share on other sites

Here's 1 of the buttons on the previous page:

<form name="armory" method="post" action="index.php?page=armory_result">
	<input type="hidden" name="itemid" value="<?=$weapons[$key]['id'];?>">
	<input type="hidden" name="itemprice" value="<?=$weapons[$key]['price'];?>">
	<input type="hidden" name="itemtype" value="weapon">
	<input type="submit" name="buy" value="Buy <?=$weapons[$key]['weapon'];?>">
	</form>

 

Note when I view the page source all the value's are correct.

 

Link to comment
Share on other sites

Should be fairly simple...

 

change:

<?php
  // run the queries for you - insert your new amount of money
  $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";

 

to:

<?php
  // run the queries for you - insert your new amount of money
  $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  die("$sqll");

 

Analyze that output for any obvious problems. If you don't see any, open up phpMyAdmin. Copy that screen output and paste it directly into a SQL box in phpMyAdmin. See if it returns an 'Affected Rows' of 0 or 1.

 

Post back your results.

 

PhREEEk

Link to comment
Share on other sites

Ok, next stage:

 

<?php
  // run the queries for you - insert your new amount of money
  $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error());
  echo "Numer of records updated: " . mysql_affected_rows();
  die();

 

PhREEEk

Link to comment
Share on other sites

Run this:

 

<?php
  // run the queries for you - insert your new amount of money
  $sqll = "UPDATE `cf_users` SET `money` = '0' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error());
  echo "Numer of records updated: " . mysql_affected_rows();
  die();

 

If you get 1 affected row, open phpMyAdmin and check the record for that ID. Does money = 0?

 

If not, we need Fox Mulder again...

 

PhREEEk

Link to comment
Share on other sites

Last try, then I'm all about 'Uncle'...

 

<?php
  // run the queries for you - insert your new amount of money
  $sqll = "SELECT * FROM `cf_users` WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $result = mysql_query($sqll);
  $row = mysql_fetch_assoc($result);
  echo "Before Update:<br><pre>";
  print_r($row);
  echo "</pre><br>After Update:<br><pre>";

  $sqll = "UPDATE `cf_users` SET `money` = '0' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error());
  $updated = mysql_affected_rows();

  $sqll = "SELECT * FROM `cf_users` WHERE `id`='" . $player_accountid . "' LIMIT 1";
  $result = mysql_query($sqll);
  $row = mysql_fetch_assoc($result);
  print_r($row);
  echo "</pre><br><br>Number of records updated: $updated";
  die();

 

PhREEEk

Link to comment
Share on other sites

Before Update:

 

Array

(

    [id] => 1

    [username] => ACE

    [password] => My Password

    => My E-mail

    [verify] => 5

    [race] => 3

    [money] => 45097155040

    [bank] => 1000

    [level] => 1

    [currentexp] => 0

    [neededexp] => 120

    [authlevel] => 3

    [currenthealth] => 100

    [currentpower] => 100

    [maxhealth] => 100

    [maxpower] => 100

    [skilllevel] => 1

    [skillpoints] => 3

    [strength] => 10

    [agility] => 10

    [intelligence] => 10

    [strikeaction] => 2147483647

    [defenceaction] => 2147483647

    [covertaction] => 2147483647

    [talentid] => 0

    [talentname] => none

    [talentlevel] => 1

    [talentpoints] => 0

    [weaponid] => 0

    [weapons] => 0

    [armorid] => 0

    [armors] => 0

    [vehicleid] => 0

    [vehicles] => 0

    [allianceid] => 0

    [alliancename] => none

    [allianceposition] => 0

    [regdate] => 2007-09-25 20:11:35

    [ammo] => 2072

    [rank] => 24

    [price_strikeops] => 134217728000

    [amount_strikeops] => 53687091200

    [level_strikeops] => 30

    [level_defenceops] => 33

    [amount_defenceops] => 429496729600

    [price_defenceops] => 1073741824000

    [price_covertops] => 134217728000

    [amount_covertops] => 53687091200

    [level_covertops] => 30

    [score] => 2147483647

)

 

 

After Update:

 

Array

(

    [id] => 1

    [username] => ACE

    [password] => My Password

    => My E-mail

    [verify] => 5

    [race] => 3

    [money] => 0

    [bank] => 1000

    [level] => 1

    [currentexp] => 0

    [neededexp] => 120

    [authlevel] => 3

    [currenthealth] => 100

    [currentpower] => 100

    [maxhealth] => 100

    [maxpower] => 100

    [skilllevel] => 1

    [skillpoints] => 3

    [strength] => 10

    [agility] => 10

    [intelligence] => 10

    [strikeaction] => 2147483647

    [defenceaction] => 2147483647

    [covertaction] => 2147483647

    [talentid] => 0

    [talentname] => none

    [talentlevel] => 1

    [talentpoints] => 0

    [weaponid] => 0

    [weapons] => 0

    [armorid] => 0

    [armors] => 0

    [vehicleid] => 0

    [vehicles] => 0

    [allianceid] => 0

    [alliancename] => none

    [allianceposition] => 0

    [regdate] => 2007-09-25 20:11:35

    [ammo] => 2072

    [rank] => 24

    [price_strikeops] => 134217728000

    [amount_strikeops] => 53687091200

    [level_strikeops] => 30

    [level_defenceops] => 33

    [amount_defenceops] => 429496729600

    [price_defenceops] => 1073741824000

    [price_covertops] => 134217728000

    [amount_covertops] => 53687091200

    [level_covertops] => 30

    [score] => 2147483647

)

 

 

 

Number of records updated: 1

Link to comment
Share on other sites

Run this code:

 

<?php
  // run the queries for you - give you your weapon
  $sql = "SELECT `weapons`, `armors`, `vehicles`
          FROM `cf_users`
          WHERE `id`= '" . $player_accountid . "'
          LIMIT 1
         ";
  $result = mysql_query($sql);
  list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result);
  $typex = $type . ',' . $item_id;
  $update = "UPDATE `cf_users` SET `$type` = '$typex' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  echo "Before Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>";
  echo "Performing Update using query: <br>$update<br><br>";  
  $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error());
  $sql = "SELECT `weapons`, `armors`, `vehicles`
          FROM `cf_users`
          WHERE `id`= '" . $player_accountid . "'
          LIMIT 1
         ";
  $result = mysql_query($sql);
  list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result);
  echo "After Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>";
  die();

 

PhREEEk

Link to comment
Share on other sites

We might want to try this code too:

 

<?php
  // run the queries for you - give you your weapon
  $sql = "SELECT `weapons`, `armors`, `vehicles`
          FROM `cf_users`
          WHERE `id`= '" . $player_accountid . "'
          LIMIT 1
         ";
  $result = mysql_query($sql);
  list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result);
  $typex = $type . ',' . $item_id;
  $update = "UPDATE `cf_users` SET `$type` = '" . mysql_real_escape_string($typex) . "' WHERE `id`='" . $player_accountid . "' LIMIT 1";
  echo "Before Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>";
  echo "Performing Update using query: <br>$update<br><br>";  
  $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error());
  $sql = "SELECT `weapons`, `armors`, `vehicles`
          FROM `cf_users`
          WHERE `id`= '" . $player_accountid . "'
          LIMIT 1
         ";
  $result = mysql_query($sql);
  list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result);
  echo "After Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>";
  die();

 

PhREEEk

Link to comment
Share on other sites

Ran the UPDATE through PHPmyAdmin with no success  :-\

 

and made the changes to my code and here is the result:

Before Update:

Weapon =

Armor =

Vehicle =

 

Performing Update using query:

UPDATE `cf_users` SET `weapons` = 'weapons,2' WHERE `id`='1' LIMIT 1

 

After Update:

Weapon =

Armor =

Vehicle =

 

Note that, before the UPDATE and after, even if the columns aren't altered, they should still have 0 (zero) in them none the less.

Link to comment
Share on other sites

What would you like to have happen here? If `cf_users` is a valid table, `weapons` is a valid field under `id`-'1', then the query UPDATE `cf_users` SET `weapons` = 'weapons,2' WHERE `id`='1' LIMIT 1 looks good to me. Did you try the mysql_real_escape_string?

 

I guess let's try this. Log into phpMyAdmin and select the table `cf_users`. Click Browse. Under record 'id' 1, click the pencil icon (selecting edit). You are presented with an edit form. Scroll down to the `weapon` field. Type in weapons,2 and save it. Let me know what happens... save any text if it errors out, or is successful. A screenshot would be ideal.

 

PhREEEk

Link to comment
Share on other sites

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.