grlayouts Posted January 14, 2007 Share Posted January 14, 2007 [code]<?phpinclude("config.php");$drugupdate = 100 * $stat[drugfact];mysql_query("update players set UTCQ=UTCQ+$drugupdate where id=$stat[id]");?>[/code]can anyone tell me why that is not updating into my database. Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 Could be any number of reasons, try some debugging.[code=php:0]mysql_query("update players set UTCQ=UTCQ+$drugupdate where id=$stat[id]") or die(mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 14, 2007 Share Posted January 14, 2007 Well for one how is id not in quotes unless it is a constant: $stat[[b]id[/b]] Quote Link to comment Share on other sites More sharing options...
Barand Posted January 14, 2007 Share Posted January 14, 2007 It also helps to set up the query as a string first so you can echo it if you have problems[code]<?php$sql = "update players set UTCQ=UTCQ+$drugupdate where id=$stat[id]";mysql_query($sql) or die(mysql_error() . ' in <br>' . $sql);?>[/code] Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 inupdate players set UTCQ=UTCQ+no idea what that means? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 now i have [code]<?phpinclude("config.php");$drugupdate = 100 * '$stat[drugfact]';$sql = "update players set UTCQ=UTCQ+'$drugupdate'";mysql_query($sql) or die(mysql_error() . ' in <br>' . $sql);?>[/code]which gives no error, but doesnt update the database either. Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 Not using a WHERE clause will update all records, are you sure thats what you want? Try...[code]<?phperror_reporting(E_ALL) ; ini_set("display_errors","1");include("config.php");$drugupdate = 100 * '$stat[drugfact]';$sql = "update players set UTCQ=UTCQ+'$drugupdate'";mysql_query($sql) or die(mysql_error() . ' in <br>' . $sql);?>[/code] Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 14, 2007 Share Posted January 14, 2007 Am I missing something? Don't you have to use quotes around a string? Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 [quote]Am I missing something? Don't you have to use quotes around a string?[/quote]Not sure which part your talking about. This line...[code=php:0]$drugupdate = 100 * '$stat[drugfact]';[/code]needs to be...[code=php:0]$drugupdate = 100 * $stat['drugfact'];[/code]though. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 14, 2007 Share Posted January 14, 2007 Exactly.I don't see why this wouldn't work:[code]<?phperror_reporting(E_ALL) ; ini_set("display_errors","1");include("config.php");$drugupdate = 100 * $stat['drugfact'];$sql = "UPDATE players SET UTCQ=UTCQ+$drugupdate";mysql_query($sql) or die(mysql_error() . ' in <br />' . $sql);?>[/code] Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 ok ive updated the code to include the $stat[code]<?phpinclude("config.php");error_reporting(E_ALL) ; ini_set("display_errors","1");$stat = mysql_fetch_array(mysql_query("select * from players"));$drugupdate = 100 * $stat['drugfact'];$sql = "UPDATE players SET UTCQ=UTCQ+$drugupdate";mysql_query($sql) or die(mysql_error() . ' in <br />' . $sql);?>[/code]still nothing updating? Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 What are you wanting to do excactly? As Ive previously said, without a WHERE clause your update statement will update ALL records, is that what you want? That code is terrible and getting worse.Also, are you getting any errors yet? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 no. the database has a field drugfacts. each player will have a number of facts. mine is 200 everyother players is 0. so i want it to times the ammount of drugs facts by 100 and update in the field UTCQ under the same 'players' table Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 [quote]i want it to times the ammount of drugs facts by 100[/quote]For each user? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 yeah., cos if they have 0 facts they will get 0 payout. Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 [code]<?phpinclude("config.php");error_reporting(E_ALL) ; ini_set("display_errors","1");$sql = "UPDATE players SET UTCQ=drugfact*100";if (mysql_query($sql)) { echo "update success";} else { die(mysql_error() . ' in <br />' . $sql);}?>[/code] Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 14, 2007 Author Share Posted January 14, 2007 but thats not difining drugfact as something from the database? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 14, 2007 Share Posted January 14, 2007 So you want to multiply everysingle person's drugs fact by 100?I would do it like:[code]<?php$sql = "UPDATE `players` SET `UTCQ`=`UTCQ`*'100'";mysql_query($sql) or die(mysql_error() . ' in <br />' . $sql);?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 [quote]but thats not difining drugfact as something from the database?[/quote]You said [i]drugfact[/i] is a field in your database. My code will take whatever value is in [i]drugfact[/i] times it by 100 and insert the total into UTCQ. Quote Link to comment 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.