Akenatehm Posted February 28, 2009 Share Posted February 28, 2009 Hey Guys, This script: #!/usr/bin/php -q <?php session_start(); $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "game"; $username = $_SESSION['username']; $connect = mysql_connect($dbhost,$dbuser,$dbpass); $selectdb = mysql_select_db($dbname); if (!$connect | !$selectdb) { die('MySQL Error ' . mysql_error()); } else { $selectplayerid = mysql_query("SELECT playerid FROM accounts"); if (!$selectplayerid) { die("MySQL Error: " . mysql_error()); } $filterplayerid = mysql_fetch_assoc($selectplayerid); $num= mysql_num_rows($selectplayerid); $i=0; while($i<$num) { $playerid = $filterplayerid['playerid']; $getmineinfo = mysql_query("SELECT * FROM userbuildings WHERE playerid = '$playerid' AND buildingid = 1"); if(!$getmineinfo) { die("MySQL Error: " . mysql_error()); } else { $filtermineinfo = mysql_fetch_assoc($getmineinfo); $buildinglevel = $filtermineinfo['level']; $gatherers = $filtermineinfo['gatherers']; $amount = $buildinglevel * $gatherers / 4; $increasegold = mysql_query("UPDATE resources SET gold = gold + '$amount'") or die(mysql_error()); } mysql_query($selectplayerid); $i++; } } ?> Doesn't insert any data into the gold field at all. I had it going before but it inserted the same amount of gold into everyone. I messed around with it and now it doesn't work at all. There seems to be no errors outputting from it. Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/ Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 you should include a WHERE clause in yoru UPDATE Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773144 Share on other sites More sharing options...
Akenatehm Posted February 28, 2009 Author Share Posted February 28, 2009 I had there and someone told me to take it out. I added it back. It's still not being added to the db. Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773146 Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 change $increasegold = mysql_query("UPDATE resources SET gold = gold + '$amount'") to $increasegold = mysql_query("UPDATE `resources` SET `gold` = `gold` + '$amount' WHERE `playerid` = '{$playerid}'") Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773148 Share on other sites More sharing options...
Akenatehm Posted February 28, 2009 Author Share Posted February 28, 2009 I did that and still nothing happens.. Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773475 Share on other sites More sharing options...
Akenatehm Posted February 28, 2009 Author Share Posted February 28, 2009 Anyone? Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773502 Share on other sites More sharing options...
RussellReal Posted March 1, 2009 Share Posted March 1, 2009 is $amount getting set? Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773564 Share on other sites More sharing options...
Akenatehm Posted March 1, 2009 Author Share Posted March 1, 2009 Yes....you can see it. $amount = $buildinglevel * $gatherers / 4; Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773568 Share on other sites More sharing options...
RussellReal Posted March 1, 2009 Share Posted March 1, 2009 I mean but is it holding any value.. try echoing it Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773570 Share on other sites More sharing options...
Akenatehm Posted March 1, 2009 Author Share Posted March 1, 2009 You were right. I didn't have data in the DB properly. Thanks for that. Link to comment https://forums.phpfreaks.com/topic/147281-solved-error-inserting-correct-details-into-database-with-script/#findComment-773572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.