Jump to content

Recommended Posts

I'm relatively new to PHP and it's all starting to really settle now. However, I'm having trouble figuring out how to do something.

 

I have a website that has information that has to be constantly added (concerts). We're hiring a friend for ten cents a show they input. My job is to figure out how to keep track of how many shows they enter. I have the whole log in system online and working, and the form submits and saves info to the database without a hitch.

 

Now what I'd like to do is to count how many shows they add per session and then have that number emailed to me after they log out. Ideas?

Link to comment
https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/
Share on other sites

Well they're logging in, meaning you have a users table?

If so, I'd suggest add a new field to that table labeled Tracker or whatever.

 

Depending on how the form for entry is set up (unless they're going through phpMyadmin?) change it so that every time they submit the form, another query is preformed that bumps up the Tracker number by one.

 

Then when they click logout, add a new snippet of code that emails you their tracker number and resets it back to zero.

 

I don't have a code onhand to give you to modify, but if you have problems making the script edits just post again.

Yeah, you can do it with PHP/MySQL.

 

The easiest would probably be using sessions - when they login, start a counter session... each time they submit a new form, increment the session variable. On logout, just email the user's name, and the session variable.

 

The other way would be a little more complicated, using MySQL. If you want to know that way, let me know and I can try to setup an example.

No, you can run a separate (or combined) query to update the # of concerts entered.

 

An idea might be: give each created event an "authorid" that is the same as his/her username.  When the form is submitted, submit the event like normal with the id of the user that's logged in as one of the columns.  You should also have a 'createdDate' as a DATETIME or TIMESTAMP data type.

 

Then you could have a cron job that runs at midnight and selects any events entered that day and groups by the userid.  That way you'd have a history of which events he/she made, as well as a count.  You could also use this to generate a summary of all events created by the user over a month/week for an invoice.

kingphilip is correct you can use sessions for the counter however, what happens if the user doesn't click logout. If they just close the window nothing happens. I would set it to store this info in the database and then set up a page where you can view it when you log in rather than having it email it to you.

EDIT: lol everyone beat me to it. ;D Go with Xtopolis' idea.

 

Yes, purely php way to accomplish this.

 

When the form is submitted for the show, php querys the mysql database to insert the data, correct? Just stick a second query right below this query that updates the users table.

 

It'd look something like this: (warning, writing this code off the top of my head!)

mysql_query("/*code to insert show information into the concert table when successfully submitted*/");

$paythem = mysql_query("SELECT Tracker FROM UsersTable WHERE user=$user")
or die(mysql_error());
//$user would be the person logged in, set it with a session variable, their use of a password or whatever else you're using to identify them with.
while (mysql_fetch_array($paythem)) {
$newTracker = $paythem['Tracker'] + 1;
}
mysql_query("UPDATE UsersTable SET Tracker=$newTracker WHERE user=$user";

 

That should work to update the Tracker number every time they submit the form.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.