Page 1 of 1

php sql update problem

Posted: Sat Feb 09, 2008 2:03 am
by raider00321
hey there, I just recently created a code which automatically generates and updates a sql database. It worked fine on my test computer, but when uploaded to my webhost I beleive the problem is that the webhost is php 4, whereas i run php 5 on my computer. Does anyone know how i can get this code to work on the webhost? The code is

Code: Select all

 
 
while($row = mysql_fetch_array($result)){
$variable=mysql_fetch_array(mysql_query("SELECT woodincome FROM buildings WHERE name='$row[name]'"))or die(mysql_error());
mysql_query("UPDATE table SET info=info+('$infoinc[infoincome]'*$row[infoname])")or die(mysql_error());
 
 
Does anyone know howi can make this run on PHP4? Or is it not working for another reason.Like i said, it works on my home test server, but not my webhost.
Thanks for any help given

Re: php sql update problem

Posted: Sat Feb 09, 2008 9:44 am
by Christopher
Which line does not work? Is there an error message?

Maybe:

Code: Select all

mysql_query("UPDATE table SET info=info+({$infoinc[infoincome]}*{$row[infoname]})")or die(mysql_error());
// or
$n = $infoinc[infoincome] * $row[infoname];
mysql_query("UPDATE table SET info=info+$n")or die(mysql_error());
 

Re: php sql update problem

Posted: Sat Feb 09, 2008 5:41 pm
by Benjamin
I believe the problem is that the latter query is using the reserved word "table" and needs to be in backticks.

Re: php sql update problem

Posted: Sat Feb 09, 2008 6:23 pm
by GuitarheadCA
Not sure what type of error it is, but if it's whitespace-related, try enclosing your query arrays with curly braces, ie. '{$row['name']}'