chordsoflife Posted January 15, 2009 Share Posted January 15, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/ Share on other sites More sharing options...
RestlessThoughts Posted January 15, 2009 Share Posted January 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737438 Share on other sites More sharing options...
chordsoflife Posted January 15, 2009 Author Share Posted January 15, 2009 Would I have to use javascript for that? "onclick"? That's essentially where my issue is. Is there a purely php/mysql way to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737446 Share on other sites More sharing options...
Philip Posted January 15, 2009 Share Posted January 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737449 Share on other sites More sharing options...
xtopolis Posted January 15, 2009 Share Posted January 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737451 Share on other sites More sharing options...
ngreenwood6 Posted January 15, 2009 Share Posted January 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737453 Share on other sites More sharing options...
Philip Posted January 15, 2009 Share Posted January 15, 2009 Good point. xtopolis' is going to be the best way, it'll take more work, but it'll be worth it in the long run (view patterns, history, etc) Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737455 Share on other sites More sharing options...
RestlessThoughts Posted January 15, 2009 Share Posted January 15, 2009 EDIT: lol everyone beat me to it. 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. Quote Link to comment https://forums.phpfreaks.com/topic/140892-counting-submits-with-php/#findComment-737461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.