0

Good morning,

I am new to programming, so I hope this is not a stupid question. I am creating a page for the music department of a small school. I want parents to be able to register, but before they can do it they need to look up their child/children's info in the database; if the information is found then they can proceed with the registration process.

Therefore, the first part of the registration process is a form that says "Look up your child". I can do this easily if there is only one student:

if(isset($_POST['submit'])) {
$child_last_name = mysqli_real_escape_string($dbc, trim($_POST['child_last_name']));
$child_date_of_birth = mysqli_real_escape_string($dbc, trim($_POST['child_date_of_birth']));
$query = "SELECT student_id, first_name, last_name FROM students where last_name = '$child_last_name' AND dob = STR_TO_DATE('$child_date_of_birth', '%m/%d/%Y')";
$data = mysqli_query($dbc, $query);
     if(mysqli_num_rows($data) != 0) {
         $children = array();
         while($row = mysqli_fetch_array($data)) {
         array_push($children, $row);
         }
    }
}

And below this I have the code for the registration form. So, my question would be, is there a way to look up information about more than 1 student and put it in the same array so that I can use that info later in the registration form for the parent (I will put the student_id in the database for the parents) I only know a little of PHP :(

Any help is GREATLY appreciated.

komodo
  • 39
  • 1
  • 7
  • Why don't you get all students at once and build a auto-complete textfield into that parent register form? They can start to type their child's name, if it doesn't pop up, it's not registered, yet. – Paul Oct 08 '14 at 14:09
  • 2
    @komodo just a piece of advice: the `mysql_*` functions are now deprecated, consider looking into PDO instead. see [why-shouldnt-i-use-mysql-functions-in-php](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for more info. – ᴍᴇʜᴏᴠ Oct 08 '14 at 14:12
  • `I will put the student_id in the database for the parents` If by this you mean you'll save the `student_id` in the `parents` table then you should read about junction tables, as they're how many-to-many relationships are handled in the database. – Alternatex Oct 08 '14 at 14:32
  • @Paul, It is a great idea, but I don't want parents (or anybody else trying to register) to see the name of the students. I would like names to be displayed only if a person knows the last name and the date of birth of the student. I am using mysqli_* instead of mysql_* is that enough? Thanks a lot! – komodo Oct 08 '14 at 15:20
  • @komodo, just add the fields for child's name and birthday to the normal registration form anyways. Upon submit, use the data provided to find the child and proceed if found. If not found, go back to the form and display an error message saying that the child was not found. – Paul Oct 09 '14 at 06:45

1 Answers1

0

Well, I think the main point to understand when programming on the web, is that the concept is different from a common application. In a common app, there is ONE application and variables are inside this ONLY app. On the web, the concept is different: each "page" is an app. So, on server side, the PHP create one page, send it to the user and... forget it. This mean when this page call back another page, the first one must tell the second "who I am" and so on. This is very important to understand that as it has a big impact on "concept" of the web site.

In your case, this specificity of Web, will create a problem: I'm John and want to register my chidren. Your idea is that I'll have to register first my children and then I would be able to register myself. The problem is that the father exist before the children... So if I register my children without being registed, the system would not be able to know these children are mines...

What I suggest (just an idea) is to create both at same time, using one form: a part for me "as dady" and a part for (eg.) 3 children. When I'll submit the system would be able to check and accept of not.

On server site, so on the destination page, you'll be able to check if it's OK for register, and save datas in 2 tables: one record in a Parent_Table with a unique id, and 1, 2 or more records in a Child_Tab for the children, each of them with a link to the parent table, using the unique id of the dady.

Hope this help

Peter
  • 1,247
  • 19
  • 33
  • Thanks for your message. Their kids will already be registered. So when parents try to register they look up their kids. I am trying to make it all in one page; The ideal thing would be if they enter information in the form to find a child and then this starts to create a list. If they want to add another child then they can type again the last name and date of birth and if the child is in the database this second child will be added to the list. Once the person is done adding children to the list then the person can continue with registration. – komodo Oct 08 '14 at 17:35
  • (all of this on the same page). After the parent is done typing registration information the id for each child will be added to the parent_table so that I can kind of link accounts using joins if I need to in the future. I hope this is kind of clear. – komodo Oct 08 '14 at 17:36
  • OK but in that case, a question: how can parent look for THEIR kids? On the other end, what you'll like to have is a rela time update of the kids list? Eg, I'm the father, I type "J" the list give me the list of all kids with name starting with "J", I select my son, and valid? If thats one option, just look here: http://stackoverflow.com/questions/12013249/populating-dropdown-menus-using-xmlhttprequest-object – Peter Oct 08 '14 at 17:48
  • The thing is that I don't want to show up kids last names due to confidentiality reasons. They look up their kids typing 2 pieces of data: last name and date of birth. So, what I am trying to do is to check the table "students" to see if there are students with the last name and date of birth entered by the parent. If there is a match, then the student's first name, last name, and id are added to a list that is displayed to the parent so that he/she can see how many children he/she is going to add during his registration process. at the end of his/her registration only the student id is added – komodo Oct 08 '14 at 17:53
  • to the "parent_table". I want to add this id in parent_table because I can use Joins using primary keys to kind of link different accounts. Once again, thanks a lot for taking the time to help me out. – komodo Oct 08 '14 at 17:54
  • If it's for a small school, OK. But for a big one, maybe it's not safe enought. You can have some "John" with same birthdate. And in that case some parent will be linked with wrong children. – Peter Oct 08 '14 at 17:57
  • Thanks for the advice Peter. I am still confused about the best way to handle this. I might have to think of other options :( – komodo Oct 08 '14 at 20:20