Page 1 of 1
mysql UPDATE in submit form
Posted: Sat Aug 19, 2006 6:11 pm
by LHOOQ
Hi, i was wondering how to update a table in my mysql database when a user checks a radio button then clicks submit.
the table id need to update is called 'points'. It is a table that will be storing users points on a site im developing.
The update would deduct a certain amount of points from that users total points score that i will set in the value of my radio button.
Anyone know the sql part of it?
Thanks
Posted: Sat Aug 19, 2006 6:37 pm
by feyd
SQL != PHP

Databases.
Re: mysql UPDATE in submit form
Posted: Mon Aug 21, 2006 3:30 am
by GM
LHOOQ wrote:Hi, i was wondering how to update a table in my mysql database when a user checks a radio button then clicks submit.
the table id need to update is called 'points'. It is a table that will be storing users points on a site im developing.
The update would deduct a certain amount of points from that users total points score that i will set in the value of my radio button.
Anyone know the sql part of it?
Thanks
Without more information, I can only give you a pseudo-query:
Code: Select all
UPDATE tablename SET points = points - $point_value WHERE username = '$user_name';
This assumes your table's primary key is username, and the information required by the query from PHP is $point_value and $user_name.
Posted: Fri Aug 25, 2006 7:59 pm
by LHOOQ
Thanks for your reply, i know nothing about mysql myself.
Sorry for being vague.
This is what i am having trouble with....
On my site i have this...
<form name="input" action="" method="post"></font>
<input type="radio" name="cost" value="{%USER_COST%}" checked="checked">
<input type ="submit" value ="Buy!">
</form>
What i dont know is where to put the UPDATE part in order to deduct the points upon hitting submit
Any clue???
Posted: Fri Aug 25, 2006 10:58 pm
by RobertGonzalez
Your UPDATE will have to take place in the code. If you are a total newbie to PHP and MySQL, then this might be a little advanced for you at this stage. In fact, if you don't know what you are doing, you could possibly do your database harm. How much experience do you have with PHP and MySQL and how much code have you written?
Posted: Sun Aug 27, 2006 2:15 pm
by LHOOQ
I know quite alot of php, but very little mysql.
I have no trouble with writing most things html off memory, and some things php.
I have a similar code that does the same function, but its totally different (if you know what i mean) + someone else coded it.
I know some mysql queries and what they do/how they work. I'm just lost when it comes to knowing where to place them in order for them to execute properly.
Posted: Sun Aug 27, 2006 7:24 pm
by RobertGonzalez
Think of your PHP code as a series of logical instructions. When you code, you are basically writing into a document rules for processing something. As you want things to happen, write them into the code in that way. It will flow logically and be a lot easier to edit later on if needed.
For your purposes, once the form is submitted (to whatever page you name in the 'action' element of the <form> tag) the action page will need to have PHP code on it that receives the passed data, validates it and then hits the database with some update instructions (queries). That is the logical flow of what you want to do.