I know helping with homework generally isn’t accepted around here, but I’ve been stuck for over a week now, so I would be more than grateful for any help. It seems simple in concept, but I can’t get from exploding the file to getting that info into an array.
The goal is to have something to compare the text entered from a form to. For example, if the name Bob is typed into the name field then there would be a way to see if Bob’s name was already on the list.
Here’s my latest attempt:
<?php
if(isset($_POST['sname'],$_POST['snumber'],$_POST['courseselect']))
{
//Has to be submitted first
$studentname = $_POST['sname'];
$studentnumber = $_POST['snumber'];
$course = $_POST['courseselect'];
if(empty($studentname) || empty($studentnumber))
{
//make sure all fields are filled in
echo "All fields must be filled in";//for if they aren't filled in
}
else
{
//if they are filled in
$studentfile = "students";
$SF = fopen($studentfile, 'r') or die("$studentfile cannot be opened for reading");
while($studentlist = fgets($SF))
{
list ($stoodname, $stoodnumber) = explode('::', $studentlist);
$testarray[] = array('$stoodname');
echo $testarray;
}
}
//end of if/else
}//end of "has to be submitted"
?>
I feel like I’m just missing something obvious 🙁
Assuming that your student file is a CSV with
::between the fields: