Click to See Complete Forum and Search --> : MySQL UPADTE Problem
tinernet
10-14-2003, 03:16 PM
IM BACK!
this shud show u just how **** i am at php i cant do jack. o wel heres the next prob! this one shud edit the database.
HELP!
<?php
$infbuy = $_POST['infbuy'];
$flambuy = $_POST['flambuy'];
$combuy = $_POST['combuy'];
$uname = $_POST['uname'];
$db = mysql_connect("localhost","epicgame","biffyclyro") or
die("Unable to connect to the server. Please try again later.");
mysql_select_db("epicgame_uk_db",$db);
$tabalt="UPDATE epic SET inf=inf+$infbuy, flam=flam+$flambuy, com=com+$combuy; WHERE uname=$uname";
mysql_query($tabalt) or die ("There was an error, possibly because the server is overloaded. Please try again.");
mysql_close();
?>
Try using UPDATE more like this:
$tabalt="UPDATE `epic` SET `inf`='$infbuy', `flam`='$flambuy', com='$combuy' WHERE `uname`='$uname'";
tinernet
10-16-2003, 01:03 PM
ok. i need the variablse $flambuy etc. to be the existing values of the fileds add a text input value, so is there a way of defining a variable as the value of a MySQL field? e.g.
$flamex=(MySQL query to get var);
$flambuy=$_POST['flambuy']+$flamex;
cheers
Yeah, you can define a variable based on the results of a MySQL query, but before I tell you how you can do it, I'll need to know what you want to get...
tinernet
10-16-2003, 03:07 PM
ok u need a url for this:
members.lycos.co.uk/epicgame/men.htm
the site is a turn based game. this page allows u to buy new infantry and stuff (btw im not tryin to treat u like a 3 yr old). i need the MySQL table im usin to be updated when u click the authenticate button, and that the existing amount of each type of soldier is increased by tthe number of soldiers bought and reduced by the numbers of soldiers sold. the cash the user has then needs to be increased or decreased by the buy/sell of value of each unit times the number of units bought or sold. as there are 3 types of units, this gets tricky as u can imagine.
also, i thinkmy layout may be screwed, which i dont need u to fix but if u could go to members.lycos.co.uk/epicgame and tel me if nethin looks screwed. im gettin an ad free host soon which should clear things up but if it dusnt work then what i thought was a really nifty idea is buggered.
thanks
Actually, just your describing what you need, with table names and row names would be more helpful. For instance, you could use something like this:
$sql = "SELECT * FROM `tablename` WHERE `id`='1'";
$results = mysql_query($sql);
$data = mysql_fetch_array($results, MYSQL_ASSOC);
$username = $data['username'];That will pull all the values for the first id, and then assign $username with the value of the row named "username".