Page 1 of 1
[SOLVED] hey, I need some help.. again :D
Posted: Mon Mar 01, 2004 9:49 pm
by Flamie
Hi, I'm trying to edit a mysql row from PHP,
Here's an exemple:
the table has 3 fields: 1-2-3
I know the value of the field 1, and I want that on the row which contains that value of 1, edit the value of 2...
I dont know if I was clear..
thx
Flamie
Re: hey, I need some help.. again :D
Posted: Mon Mar 01, 2004 10:05 pm
by tim
Flamie wrote:I dont know if I was clear..
i dont know if it cause its so late here or what, but cant make heads from tails outta that...
Perhaps some code would helpme/others a bit better?
Posted: Mon Mar 01, 2004 10:08 pm
by Illusionist
i'm not sure, but what i think he is asking is how to edit value 2 where value1 = whatever. soemthing like
Code: Select all
UPDATE yourTbl SET value2=whatever WHERE value1=whatever
Posted: Mon Mar 01, 2004 10:12 pm
by Flamie
field1 field2 field3
abc 123 ttt
abc 12 tt
ab 123 t
ab 12 tt
ab 1 ttt
a 123 tt
a 123 t
Let's say this is a table

I want to change field 3 to rrr where field 1 is 'abc' and field 2 is '12'
I hope Its more clear

Flamie
Posted: Mon Mar 01, 2004 10:19 pm
by tim
oh... What about making a change to your table by adding a "id" colum that is autoincremented, so you'll have a special number to refer to each row.
your above table would look like:
1 abc 123 ttt
2 abc 12 tt
3 ab 123 t
4 ab 12 tt
5 ab 1 ttt
6 a 123 tt
7 a 123 t
Then you can use code:
Code: Select all
<?php
UPDATE table_name SET value#=whatever WHERE id=whatever number
?>
this code is flexible and is a better approach for you I think.
Posted: Mon Mar 01, 2004 10:24 pm
by Flamie
I have ID's for all my tables.
But I need to find the ID which will take 2 times more time.
so I have to find the ID of where field 1 ='abc' and field2='12', then look for field3 where ID='theidIfound'.
Does the word 'AND' works in mysql ?
exemple:
UPDATE table_name SET value#=whatever WHERE field1=whatever number AND field2=whatever
does tha twork ?
thx
Flamie
Posted: Mon Mar 01, 2004 10:25 pm
by andre_c
Yes, it does work:
Code: Select all
UPDATE table_name SET field3='rrr' WHERE field1='abc' AND field2='12'
Posted: Mon Mar 01, 2004 10:38 pm
by Flamie
thx

but I still have a problem.
its giving me errors on thoses :
Code: Select all
<?php
mysql_query("UPDATE clan_reg SET wins='$newwin' WHERE tag='$_POST[winningclan]'");
mysql_query("UPDATE clan_reg SET losses='$newlos' WHERE tag='$_POST[losingclan]'");
mysql_query("UPDATE clan_reg SET games='$addgame1' WHERE tag='$_POST[winningclan]'");
mysql_query("UPDATE clan_reg SET games='$addgame1' WHERE tag='$_POST[losingclan]'");
mysql_query("UPDATE clan_reg SET points='$addscore' WHERE tag='$_POST[winningclan]'");
Do I have to put something before mysql_query ?
Flamie
?>
Posted: Mon Mar 01, 2004 10:46 pm
by Flamie
And I also get this error :
Fatal error: Unsupported operand types in /home/wormahol/public_html/ecl/report.php on line 144
here:
$newwin = $newwin + 1 ;
Posted: Mon Mar 01, 2004 10:53 pm
by Flamie
YAY I fixed it

thx a lot guys for the time and help

Posted: Mon Mar 01, 2004 10:55 pm
by andre_c
You should first save the posts to variables:
Code: Select all
$winningclan = $_POSTї'winningclan'];
and then
Code: Select all
mysql_query("UPDATE clan_reg SET wins='$newwin' WHERE tag='$winningclan'");
Also, can you add 'or die(mysql_error()); ' to your queries? in order to show any SQL error if there is one.