php functions not updating the mysql database
i have a question that im not able to find a workaround. i have the following :
db("select * from {$game}_stars where event_random = '11'");
$sn_sys = dbr();
if($sn_sys['event_random'] == 11)
dbn("update {$game}_stars set event_random = 6 where event_random = '11, metal = '583720', fuel='948372', star_name = 'SuperNova Remnant' where star_id = '$sn_sys[star_id]'");
dbn("insert into {$game}_news (timestamp, headline, login_id) values (".time().",'The star in <b class=b1>system $sn_sys[star_id]</b> has exploded destroying everything in the system, and leaving a <b class=b1>Supernova Remnant</b> which is extremly rich in metals and fuel. All adjoining systems have also recieved generous quantities of minerals. We believe the SuperNova Remnant will turn into a <b>Blackhole</b> over due course.<font color=lime>- - - Science Institute of Sol - - -</font>','-11')");
#take out non-eps.
db2("select * from {$game}_ships where location = '$sn_sys[star_id]' && login_id !='1'");
while ($ship_sn = dbr()) {
if ($ship_sn['shipclass'] != 2) {
dbn("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'SuperNova','$ship_sn[login_id]','$ship_sn[login_id]','Your ship the <b class=b1>$ship_sn[ship_name]</b> was destroyed by an exploding star (<b>Supernova</b>) in system #<b>$ship_sn[location]</b>')");
dbn("delete from {$game}_ships where ship_id = '$ship_sn[ship_id]'");
dbn("insert into {$game}_news (timestamp, headline, login_id) values (".time().",'$ship_sn[login_name] lost a $ship_sn[class_name] to the SuperNova in system #<b>$ship_sn[location]<b>','$ship_sn[login_id]')");
} else {
dbn("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'SuperNova','$ship_sn[login_id]','$ship_sn[login_id]','Your <b>Escape Pod</b> was near a star when it exploded. Fortunatly is was not hurt by the explosion, but was flung to a different system. Some well-wisher then brought you to system #1.')");
dbn("update {$game}_users set location = '1' where ship_id = '$ship_sn[ship_id]'");
dbn("update {$game}_ships set location = '1' where login_id = '$ship_sn[login_id]'");
}
}
#take out non admin planets
db2("select * from {$game}_planets where location = '$sn_sys[star_id]' && owner_id != '1'");
while ($planet_sn = dbr2()) {
dbn("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'SuperNova','$planet_sn[owner_id]','$planet_sn[owner_id]','Your planet (<b class=b1>$planet_sn[planet_name]</b>) was oblterated by an exploding star (<b>Supernova</b>) in system #<b>$planet_sn[location]. It no longer excists, nor does anything that was on it.')");
dbn("delete from {$game}_planets where planet_id = $planet_sn[planet_id]");
dbn("insert into {$game}_news (timestamp, headline, login_id) values (".time().",'The planet $planet_sn[planet_name] was totally destroyed by the SuperNova in system #<b>$planet_sn[location]<b>','$planet_sn[owner_id]')");
}
#move users to sol or next ship
db2("select * from {$game}_users where location = '$sn_sys[star_id]' && login_id > '3' && ship_id != 1");
while($users = dbr2()) {
db("select * from {$game}_ships where login_id = '$users[login_id]' && login_id != 1");
if($other = dbr()) {
dbn("update {$game}_users set ship_id = '$other[ship_id]', location = '$other[location]' where login_id = '$other[login_id]'");
dbn("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'SuperNova','$users[login_id]','$users[login_id]','Command was transfered to the <b class=b1>$other[ship_name]</b>.')");
} else {
dbn("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'SuperNova','开发者_StackOverflow中文版$users[login_id]','$users[login_id]','You ejected in an escape pod.')");
dbn("insert into {$game}_ships (ship_name, login_id, login_name, shipclass, class_name, location, point_value) values('Escape Pod','$users[login_id]','$users[login_name]',2,'Escape Pod','1',5)");
dbn("select * from {$game}_ships where login_id = '$users[login_id]'");
$ship_id = dbr();
dbn("update {$game}_users set location = '1', ship_id ='$ship_id[ship_id]' where login_id = '$users[login_id]'");
}
}
db("select * from {$game}_stars where star_id = '$sn_sys[star_id]'");
$link = dbr();
$link_1 = $link['link_1'];
$link_2 = $link['link_2'];
$link_3 = $link['link_3'];
$link_4 = $link['link_4'];
$link_5 = $link['link_5'];
$link_6 = $link['link_6'];
dbn("update {$game}_stars set fuel= fuel +'103482', metal= metal+'12354' where star_id != '1' && star_id != 0 && star_id = '$link_1'");
dbn("update {$game}_stars set fuel= fuel +'95444', metal= metal+'56484' where star_id != '1' && star_id != 0 && star_id = '$link_2'");
dbn("update {$game}_stars set fuel= fuel +'74452', metal= metal+'46877' where star_id != '1' && star_id != 0 && star_id = '$link_3'");
dbn("update {$game}_stars set fuel= fuel +'37353', metal= metal+'106210' where star_id != '1' && star_id != 0 && star_id = '$link_4'");
dbn("update {$game}_stars set fuel= fuel +'74523', metal= metal+'68757' where star_id != '1' && star_id != 0 && star_id = '$link_5'");
dbn("update {$game}_stars set fuel= fuel +'63452', metal= metal+'83254' where star_id != '1' && star_id != 0 && star_id = '$link_6'");
print "<br />Supernova in $sn_sys[star_id] went bang.<br />";
}
this script is set so it inserts a message in the database with the event specs and , of course to run the queries.
Now, only the
insert into {$game}_news
seems to get processed and everything else is not.
here are my db functions
function db($string) {
global $query;
$query = mysql_query($string);
}
function dbr()
{
global $query;
$fetched = $query->fields;
return $fetched;
}
function db2($string) {
global $query2;
$query2 = mysql_query($string);
}
function dbr2()
{
global $query2;
$fetched2 = $query2->fields;
return $fetched2;
}
function dbn
function dbn($string) {
mysql_query($string);
}
Any ideas on why and any possible solutions? Thank you for reading.
Could you try to change '$ship_sn[ship_id]'
with '{$ship_sn[ship_id]}'
?
while ($ship_sn = dbr2()) {
- i think it helps. But i think you should rewrite your functions.
精彩评论