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. Quote 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 Quote 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. Quote 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}'") Quote 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.. Quote 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? Quote 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? Quote 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; Quote 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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.