Jump to content

[SOLVED] Error Inserting Correct Details into Database With Script


Akenatehm

Recommended Posts

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.

change

 

$increasegold = mysql_query("UPDATE resources SET gold = gold + '$amount'")

 

to

 

$increasegold = mysql_query("UPDATE `resources` SET `gold` = `gold` + '$amount' WHERE `playerid` = '{$playerid}'")

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.