Web Hosting Talk







View Full Version : can i do this/// PHP


Jouninshinobi
03-24-2005, 08:06 PM
can i use a variable to update

$upp2="UPDATE equip SET '$userstats3[equip]'='$totalcost2[name]' WHERE name='$userstats3[playername]'";


and if I can what is wrong cause i keep gettin an error

Wojtek
03-24-2005, 08:18 PM
$upp2="UPDATE equip SET ".$userstats3[equip]."=".$totalcost2[name]." WHERE name=".$userstats3[playername].";

try this

Jouninshinobi
03-24-2005, 08:29 PM
didn't work there was no error but it didn't add it to the table

Syphic
03-24-2005, 10:02 PM
Try this...


$upp2="UPDATE equip SET ".$userstats3[equip]."='".$totalcost2[name]."' WHERE name='".$userstats3[playername]."'";

fastduke
03-24-2005, 10:51 PM
So do you know what the sql statement actually looks like? Do you know the data well?

Tip
$upp2="UPDATE equip SET '$userstats3[equip]'='$totalcost2[name]' WHERE name='$userstats3[playername]'";

and instead of doing a :
mysql_query($upp2) or die ("Error : " . mysql_error())

do

echo $upp2

Now you could see any obvious sql syntax errors plus any wrong data(like column names or something)

Jouninshinobi
03-25-2005, 10:07 AM
I did all of that but it dosen't seem to put it in the table

Jouninshinobi
03-25-2005, 10:38 AM
ok I couldn't figure that one out so I decided to skip it and try this one


$gethouse="update 'lands' set '$type'='$amt2[$type]'+'$amount' where name='$player'";
echo "$gethouse";
mysql_query($gethouse);


When I echo it everything is working but when I look at my tables there is no change.

Wynex
03-25-2005, 02:55 PM
Try the same thing without using arrays. Store the array-var in a $var before you make the query.

krumms
03-25-2005, 03:32 PM
Originally posted by Jouninshinobi
ok I couldn't figure that one out so I decided to skip it and try this one


$gethouse="update 'lands' set '$type'='$amt2[$type]'+'$amount' where name='$player'";
echo "$gethouse";
mysql_query($gethouse);


When I echo it everything is working but when I look at my tables there is no change.

Your query _is_ broken and I'm very surprised you're not getting any error messages:


UPDATE `lands` SET `$type`='$amt2[$type]'+$amount WHERE name='$player';


Note the difference between backticks (`) and single quotes ('). Quotes encapsulate string values. Backticks are used to encapsulate MySQL entities (table names, column names, etc.).

I'm not sure if you intended $amount to have backticks or quotes around it, you'll have to work that out for yourself.

Also, you should really be using addslashes/stripslashes here as appropriate.