[SOLVED] hey, I need some help.. again :D

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
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

[SOLVED] hey, I need some help.. again :D

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Re: hey, I need some help.. again :D

Post 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?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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 :D
Flamie
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Yes, it does work:

Code: Select all

UPDATE table_name SET field3='rrr' WHERE field1='abc' AND field2='12'
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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

?>
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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 ;
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

YAY I fixed it :) thx a lot guys for the time and help :D
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

You should first save the posts to variables:

Code: Select all

$winningclan = $_POST&#1111;'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.
Post Reply