Jump to content

[SOLVED] Error Inserting Correct Details into Database With Script


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}'")

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.