Php sql更新不起作用

时间:2014-05-09 20:06:30

标签: php mysql

这是一个有趣的问题我没事,我有一个代码:

function Rotuse($building){
global $lang, $wg_village, $db;
$village_id=$wg_village->id;
includelang("musu"); //kisau nagus
$parse=$lang; //kisau nagus
$rs1zn=6400;
$rs2zn=6650;
$rs3zn=5940;
$rs4zn=1340;

$parse["rs1"]=$rs1zn;
$parse["rs2"]=$rs2zn;
$parse["rs3"]=$rs3zn;
$parse["rs4"]=$rs4zn;

if(isset($_POST['uzsakyti1'])){
    if($wg_village->rs1>=$rs1zn && $wg_village->rs2>=$rs2zn && $wg_village->rs3>=$rs3zn && $wg_village->rs4>=$rs4zn){
        //$sql="UPDATE wg_villages SET rs1=rs1-'".$rs1zn."', rs2=rs2-$rs2zn, rs3=rs3-$rs3zn, rs4=rs4-$rs4zn WHERE id=$village_id";
        $sql="UPDATE wg_villages SET rs1=100 WHERE id=80271";
        $db->setQuery($sql);
        $db->query();

    }else{
        echo "resursu nera";
    }
}



$parse['id']=$building->index;
return parsetemplate(gettemplate('rotuse_body'), $parse);
}

这里的sql更新不起作用但是如果我将相同的代码放到新文件中并直接访问它就可以实例:

    <?php
$db1= @mysql_connect('localhost', 'login', 'password') or die(mysql_error());
@mysql_select_db('vnzn') or die(mysql_error());
mysql_query('SET NAMES utf8');

$rs1azn=29700;
$rs2azn=33250;
$rs3azn=32000;
$rs4azn=6700;
$village_id=80271;
?>
<form action="" method="post">
<br/><input width="80" type='submit' height='20' value='{uzsakyti_svente}' name='uzsakyti1'></form><br/>
<?php

if(isset($_POST['uzsakyti1'])){
//mysql_query("UPDATE wg_villages SET rs1=rs1-$rs1zn, rs2=rs2-$rs2zn, rs3=rs3-$rs3zn, rs4=rs4-$rs4zn WHERE id=$village_id");
mysql_query("UPDATE wg_villages SET rs1=100 WHERE id=80271");
echo "ideta!";
var_dump($rs4azn);

}


exit; 






?>

它有效我不明白为什么,这个代码有什么问题?

EDIT VAR DUMP:

尝试了var dump $ db我得到了这个:

object(og_database)#1 (13) {["_sql"]=> string(45) "UPDATE wg_villages SET rs1=100 WHERE id=80271" ["_errorNum"]=> int(0) ["_errorMsg"]=> string(0) "" ["_table_prefix"]=> string(3) "wg_" ["_resource"]=> resource(5) of type (mysql link) ["_cursor"]=> bool(true) ["_debug"]=> int(0) ["_limit"]=> int(0) ["_offset"]=> int(0) ["_ticker"]=> int(0) ["_log"]=> array(0) { } ["_nullDate"]=> string(19) "0000-00-00 00:00:00" ["_nameQuote"]=> string(1) "`" } 

0 个答案:

没有答案