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.
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