[SOLVED] hey, I need some help.. again :D
Moderator: General Moderators
[SOLVED] hey, I need some help.. again :D
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
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
i dont know if it cause its so late here or what, but cant make heads from tails outta that...Flamie wrote:I dont know if I was clear..
Perhaps some code would helpme/others a bit better?
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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=whateveroh... 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:
this code is flexible and is a better approach for you I think.
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
?>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
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
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
Yes, it does work:
Code: Select all
UPDATE table_name SET field3='rrr' WHERE field1='abc' AND field2='12'thx
but I still have a problem.
its giving me errors on thoses :
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
?>- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
You should first save the posts to variables:
and then
Also, can you add 'or die(mysql_error()); ' to your queries? in order to show any SQL error if there is one.
Code: Select all
$winningclan = $_POSTї'winningclan'];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.