jay93 — 2013-03-05T06:13:14-05:00 — #1
I've moved this post into its own thread, as it really is a separate topic.
This was split from http://www.sitepoint.com/forums/showthread.php?986682-weird-issue-PASSWORD-RESET! (so reading that thread may help)
i was working on this website, where teachers can publish students' marks...my plan is to let the teacher open the mysql table and update the column "marks" for each "username" of id "id"... and anytime the marks are updated, each student gets an email... is my logic right? and is there any other way i can go about this??
- regarding the emailing part, i have just conjured the idea, but i dont have much idea on how to implement it... could you please give me some hints or tell me of some code?
i know i've disturbed you for almost a week now, but this is kind of the last issues i am on, and then i ll be taking a very long break... my sincerest gratitude to you...:)
cpradio — 2013-03-05T07:04:07-05:00 — #2
Do you have any table schemas (structures) you can share?
This may be terminology issue, but do you really plan on letting the teachers open/update the MySQL table directly or do you plan to put a form in front of it?
As for the e-mailing part, that should be simply enough, just use mail()
jay93 — 2013-03-05T08:01:01-05:00 — #3
[Inline] [ Edit ] [ Create PHP Code ]
Name Type Collation Attributes Null Default Extra Action
1 id int(10) UNSIGNED No None AUTO_INCREMENT Change Drop Browse distinct values Primary Unique Index Spatial Fulltext More
2 username varchar(255) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext More
3 email varchar(255) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext More
4 security varchar(255) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext More
5 marks int(255) No None Change Drop Browse distinct values Primary Unique Index Spatial
this is my table in phpmyadmin, and actually the ideal thing would have been to present teachers with a form to insert marks, but i m not sure on how to do that, so the raw plan i had was to make the teachers edit the mysql table...sounds pretty crude and primitive though...
2.and regarding the mail(), could you please explain more on how to use that function. for instance like
send mail""" if ''' table is updated"''' to all members in the table....
cpradio — 2013-03-05T08:15:57-05:00 — #4
Agreed, a form would be simple enough (if that interests you). You will simply query the table for all records, loop through them generating your form entries, one thing you need to be sure you do is treat them as an array of form items with names like "marks[<?php echo $row['id']; ?>]" so you know which id the marks applies to.
You can;t easily send an email from MySQL, there are options, but using a form for the updates would make it more seamless (in my opinion).
If you decide to go with a form for updating marks, I can help you through the entire process. If you want to the trigger approach as outlined in the link above, then you will need to develop a script that runs on a cronjob to send emails accordingly (I can help with that too).
Let me know which way you want to take this project.
jay93 — 2013-03-05T09:21:29-05:00 — #5
thank you very much... i really needed someone to guide me through this...regarding the form, the issue i had in mind was if we made such a form, will it be accessible to students too?? because if that happens then students will be able to change their marks, right?
and about the email thingy, actually i was planning to do it through php, same way as my previous website (remember the portfolio and the password reset stuff)...so basically,
i ll have a php controller, and a template.... much like reset.php (controller), and reset_form( template) from above... in fact i'm building this new website same way as the old, so i still have my old files config.php, login.php. logout.php, etc...just like the previous one... and in this new website, i m using the same reset method as the prev one from reset.php (remember??) to enable students to reset their passwords...
jay93 — 2013-03-05T09:26:58-05:00 — #6
.............................. and right now i have three folders .... html (which contains 3 folders called
and js respectively, and 6 files namely
pass.php (just like above)
2nd folder is "includes" which contains constants.php, functions.php and config.php
3rd folder called templates (contains
portfolio.php ((I AM GOING TO CHANGE THIS TO STH LIKE A PAGE WHERE STUDENTS WILL SEE THEIR MARKS AND OTHER STUDENT RESOURCES LIKE NOTICES, ANNOUNCEMENTS, ETC),
cpradio — 2013-03-05T09:50:04-05:00 — #7
Do you have a way to tell if the logged in user is a student or a teacher? If you do, you just simply have to validate they are a teacher, then show the page, otherwise, show an Access Denied message/page.
That would work, so long as your initial view is showing a form for the teacher to fill out, and after it processes the entry, it kicks off an email to the student. Thus making it so the teacher can update the marks within the page.
jay93 — 2013-03-05T10:04:38-05:00 — #8
actually i have no idea on how to distinguish between students and teachers???could you please help me with that/?
2ndmouse — 2013-03-05T10:33:24-05:00 — #9
Presumably, your db will differentiate between students and teachers. If so, you could add a login page which checks the db on submit. If the login is for a teacher, display the form, if not display a rejection.
jay93 — 2013-03-05T10:53:54-05:00 — #10
one sec, so if this is my code for login.php how can i modify it to cater for teachers?? and the new database i create for teachers, called "teachers", do i keep the same columns as those for students, i mean identical to them?? like "id", username, security, email, hash??
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
// validate submission
apologize("You must provide your username.");
else if (empty($_POST["password"]))
apologize("You must provide your password.");
// query database for user
$rows = query("SELECT * FROM users WHERE username = ?", $_POST["username"]);
// if we found user, check password
if (count($rows) == 1)
// first (and only) row
$row = $rows;
// compare hash of user's input against hash that's in database
if (crypt($_POST["password"], $row["hash"]) == $row["hash"])
// remember that user's now logged in by storing user's ID in session
$_SESSION["id"] = $row["id"];
// redirect to portfolio
// else apologize
apologize("Invalid username and/or password.");
// else render form
render("login_form.php", ["title" => "Log In"]);
cpradio — 2013-03-05T10:55:44-05:00 — #11
Before we get into that, can you provide the schema/structure for your users table?
jay93 — 2013-03-05T11:01:32-05:00 — #12
cpradio — 2013-03-05T11:05:43-05:00 — #13
Okay, my recommendation would be to add a new column to that table that designates if the user is a student or a teacher.
jay93 — 2013-03-05T11:10:21-05:00 — #14
okay, so what should the type of this new column be?? should it be varchar, or a boolean??
cpradio — 2013-03-05T11:13:50-05:00 — #15
Okay, first thing to do when defining a new column is to consider what types of values you want it to hold. So right now you definitely know you need to know the difference between a Student username and a Teacher username, what about an Administrator or Principal? Would those designations be helpful later on?
If so, I'd make the column varchar(20) and store one of the following per record, 'Student', 'Teacher', 'Principal', 'Administrator'
jay93 — 2013-03-05T11:21:39-05:00 — #16
for now, only teachers and students will suffice...
so is this fine, for the table users (for students) ?? and what about teachers' table?
cpradio — 2013-03-05T11:24:39-05:00 — #17
You can use the same table for both. So I'd rename the student column to be "user_type".
Then when you insert a student, you will populate user_type with Student, and when you input a teacher, you will populate it with Teacher.
jay93 — 2013-03-05T11:32:28-05:00 — #18
sounds good, so now there is an issue with registartion too i guess? because the user will have to specify whether he is a teacher or a student, right?
wouldnt it be better if we like just added some specific teachers to the table, so that only they can see the form when they register, instead of making it open for teachers to register? what do you suggest?
cpradio — 2013-03-05T11:40:17-05:00 — #19
That is a valid point. So if you take that approach you will want to create a Teachers table, with a single column (until you want to store more data)
userid int not null
Do not make it auto-increment, it is going to store the id from the user table, so it knows which user to identify as a teacher.
jay93 — 2013-03-05T11:47:23-05:00 — #20
do you mean a table with a single column like the below?
next page →