Forum Moderators: coopster

Message Too Old, No Replies

update a field in a database

         

rookie2

6:10 am on Aug 28, 2007 (gmt 0)

10+ Year Member



I do not know hardly anything about php.
I can connect to a database and thats about it.
I need a script where I can update a field in database.

Lets say the database is called "traffic".
The table in traffic I need to make changes in is "members"
The field I need to update is "credits"

The problem is I have a lot of members that need the credits field
updated to the same amount.

So I need to be able to put in a form a list of "members"(line by line)
and upon submit it updates each members credit field.

Does anyone know where I can get that form made up?

Habtom

7:47 am on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Does anyone know where I can get that form made up?

But I can tell you how you can create it:

Lets say the database is called "traffic".
The table in traffic I need to make changes in is "members"
The field I need to update is "credits"

Assuming you have made the connection.

$credit = $_REQUEST['credit'];
$member_id = $_REQUEST['member_id'];

If you wish to update one by one:
$query = "UPDATE members SET credits = ". $credit ." WHERE member_id = ". $member_id ."";
mysql_query($query);

If you wish to update many members at once:
You can pass the members list or ids comma separated, explode it, and loop to run the update query a number of times, or include those ids as where conditions in the query.

Habtom

rookie2

5:19 am on Aug 29, 2007 (gmt 0)

10+ Year Member



If you wish to update many members at once:
You can pass the members list or ids comma separated, explode it, and loop to run the update query a number of times, or include those ids as where conditions in the query.

That is the part I do not understand.

I need to be able to copy and paste into a form a list of "members" (one per line) and then click a submit button.
Then it takes each member and changes their credits field.
All credit fields will get the same amount.

I can currently do one at a time but I have hundreds to do.

Thanks for the reply.

If you can show me how to do it with a list of members (one per line)I would be so grateful.

I just have no clue about looping or exploding.

jatar_k

12:33 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use a similar query

$query = "UPDATE members SET credits = ". $credit ." WHERE member_id IN (". $member_id . ")";

then $member_id would need to be a comma seperated list of ids

you could paste them into a textarea and then process that, if you pasted a list of ids seperated by commas then it would be even easier

make a textarea
paste a list in there
then echo it on your processing script to see how it needs to be transformed