mysql UPDATE in submit form

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
LHOOQ
Forum Newbie
Posts: 8
Joined: Wed Aug 16, 2006 3:39 pm

mysql UPDATE in submit form

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SQL != PHP Image

:arrow: Databases.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Re: mysql UPDATE in submit form

Post 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.
LHOOQ
Forum Newbie
Posts: 8
Joined: Wed Aug 16, 2006 3:39 pm

Post 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???
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
LHOOQ
Forum Newbie
Posts: 8
Joined: Wed Aug 16, 2006 3:39 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply