php sql update problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raider00321
Forum Newbie
Posts: 1
Joined: Sat Feb 09, 2008 1:54 am

php sql update problem

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php sql update problem

Post 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());
 
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: php sql update problem

Post by Benjamin »

I believe the problem is that the latter query is using the reserved word "table" and needs to be in backticks.
GuitarheadCA
Forum Newbie
Posts: 20
Joined: Fri Jul 13, 2007 12:59 am

Re: php sql update problem

Post 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']}'
Post Reply