0

Hey guys,

I just need a bit of help figuring out what the best way to go about the following using PHP/MySQL:

It's basically a registration component

So I have a button, let's call it "add_to_list" and I need this button to control a couple of things. When a user clicks the "add_to_list" button it will check to see if that user has done so before, if not it will add that user to an "attending" field in the DB and it will subtract 1 from a field in a db called "spots_left" (let's say there is 10 spots). Once the "spots_left" field hits 0 the "add_to_list" button will no longer.

How would this be done? New to PHP and any help would be greatly appreciated : )

Thanks

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by drewpark88
1

You'll need to write some functions in PHP that do the mysql work.
add_to_list($user), user_in_list($user), decrease_spots_left(), spots_left().

Then, you'll need to check if there's $_POST['email'] (I guess? Or something else, whatever is posted), and if so, execute those functions:

if(spots_left() && !user_in_list($user)) {
  add_to_list($user);
  decrease_spots_left();
}

Also, if(!spots_left()) you'll have to hide or disable the button.

Edited by twiss: n/a

Votes + Comments
Very Helpful!
0

Thank you so much twiss! That's exactly what I needed to know, you are awesome! One more quick question if you don't mind.

Let's say I have an Database table for "events" and I add new events to change out the old events. How would I do this to make it unique so the user can print out a invitation number for each event they get added to? And even though they got added to the previous event and can no longer resubmit the button, I need them to be able to submit for the new event.

I was thinking I might use the "id" field in the "events" db to make each event unique. Then add that id from the new event to the "add_to_list" button? Not really sure the logic on this, either way you have helped a bunch :)

You'll need to write some functions in PHP that do the mysql work.
add_to_list($user), user_in_list($user), decrease_spots_left(), spots_left().

Then, you'll need to check if there's $_POST['email'] (I guess? Or something else, whatever is posted), and if so, execute those functions:

if(spots_left() && !user_in_list($user)) {
  add_to_list($user);
  decrease_spots_left();
}

Also, if(!spots_left()) you'll have to hide or disable the button.

Edited by drewpark88: n/a

1

Can a user have multiple events, or can an event have multiple users? Or both? Anyway, you'll have to give one of them an ID column, and then give the other a user_ID or event_ID column. That way, you can make get_events_by_user or get_user_by_event or whatever you need.

0

Oh I see. Well the user can attend multiple events and the events allow multiple users to attend so I guess both. Thank you again I really appreciate the help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.