Writing dynamic checkbox list, How can I submit the checked boxes? [closed]
I am producing a list of students so a user can mark their absence. I want to have a form which has the checkbox and their name for each student on the users roster. I have code to generate that. Once I hit submit, how can I write a query that uses all the checked boxes to add the dates to the database with each student's id?
Here is my code:
//set up the database
$servername = "localhost";
$usernameDB = "root";
$passwordDB = "";
$nameDB = "teacheasy";
//connect to the database
$connection = new mysqli($servername, $usernameDB, $passwordDB, $nameDB);
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName' FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
echo "<form method='post'>";
echo"<table>";
echo"<tr>
<td><b>Mark Today's Absesences Only</b></td>
</tr>";
$nameCount = 0;
while($row = mysqli_fetch_assoc($resultListStudents)){
echo"<tr><td><input type='checkbox' name='student". $nameCount ."'>{$row['StudentName']}</td></tr>";
$nameCount++;
}
echo "</table>";
echo "<button type='submit' name='submitAbsences' class='navButton'>Submit Absences</button>";
echo "</form>";
if(isset($_POST['submitAbsences'])){
}
Here is the output I have.
Click this, I cant put pictures yet due to being a newer account.
php html mysql
closed as too broad by Funk Forty Niner, miken32, pushkin, Akintunde-Rotimi, Nic3500 Nov 20 '18 at 0:47
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am producing a list of students so a user can mark their absence. I want to have a form which has the checkbox and their name for each student on the users roster. I have code to generate that. Once I hit submit, how can I write a query that uses all the checked boxes to add the dates to the database with each student's id?
Here is my code:
//set up the database
$servername = "localhost";
$usernameDB = "root";
$passwordDB = "";
$nameDB = "teacheasy";
//connect to the database
$connection = new mysqli($servername, $usernameDB, $passwordDB, $nameDB);
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName' FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
echo "<form method='post'>";
echo"<table>";
echo"<tr>
<td><b>Mark Today's Absesences Only</b></td>
</tr>";
$nameCount = 0;
while($row = mysqli_fetch_assoc($resultListStudents)){
echo"<tr><td><input type='checkbox' name='student". $nameCount ."'>{$row['StudentName']}</td></tr>";
$nameCount++;
}
echo "</table>";
echo "<button type='submit' name='submitAbsences' class='navButton'>Submit Absences</button>";
echo "</form>";
if(isset($_POST['submitAbsences'])){
}
Here is the output I have.
Click this, I cant put pictures yet due to being a newer account.
php html mysql
closed as too broad by Funk Forty Niner, miken32, pushkin, Akintunde-Rotimi, Nic3500 Nov 20 '18 at 0:47
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am producing a list of students so a user can mark their absence. I want to have a form which has the checkbox and their name for each student on the users roster. I have code to generate that. Once I hit submit, how can I write a query that uses all the checked boxes to add the dates to the database with each student's id?
Here is my code:
//set up the database
$servername = "localhost";
$usernameDB = "root";
$passwordDB = "";
$nameDB = "teacheasy";
//connect to the database
$connection = new mysqli($servername, $usernameDB, $passwordDB, $nameDB);
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName' FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
echo "<form method='post'>";
echo"<table>";
echo"<tr>
<td><b>Mark Today's Absesences Only</b></td>
</tr>";
$nameCount = 0;
while($row = mysqli_fetch_assoc($resultListStudents)){
echo"<tr><td><input type='checkbox' name='student". $nameCount ."'>{$row['StudentName']}</td></tr>";
$nameCount++;
}
echo "</table>";
echo "<button type='submit' name='submitAbsences' class='navButton'>Submit Absences</button>";
echo "</form>";
if(isset($_POST['submitAbsences'])){
}
Here is the output I have.
Click this, I cant put pictures yet due to being a newer account.
php html mysql
I am producing a list of students so a user can mark their absence. I want to have a form which has the checkbox and their name for each student on the users roster. I have code to generate that. Once I hit submit, how can I write a query that uses all the checked boxes to add the dates to the database with each student's id?
Here is my code:
//set up the database
$servername = "localhost";
$usernameDB = "root";
$passwordDB = "";
$nameDB = "teacheasy";
//connect to the database
$connection = new mysqli($servername, $usernameDB, $passwordDB, $nameDB);
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName' FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
echo "<form method='post'>";
echo"<table>";
echo"<tr>
<td><b>Mark Today's Absesences Only</b></td>
</tr>";
$nameCount = 0;
while($row = mysqli_fetch_assoc($resultListStudents)){
echo"<tr><td><input type='checkbox' name='student". $nameCount ."'>{$row['StudentName']}</td></tr>";
$nameCount++;
}
echo "</table>";
echo "<button type='submit' name='submitAbsences' class='navButton'>Submit Absences</button>";
echo "</form>";
if(isset($_POST['submitAbsences'])){
}
Here is the output I have.
Click this, I cant put pictures yet due to being a newer account.
php html mysql
php html mysql
asked Nov 19 '18 at 20:35
MattMatt
45
45
closed as too broad by Funk Forty Niner, miken32, pushkin, Akintunde-Rotimi, Nic3500 Nov 20 '18 at 0:47
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Funk Forty Niner, miken32, pushkin, Akintunde-Rotimi, Nic3500 Nov 20 '18 at 0:47
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you set the names of the checkboxes toname="students"
PHP can store all the names in an array by using the list function. Once it is in an array you can update looping through the array.
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you set the names of the checkboxes toname="students"
PHP can store all the names in an array by using the list function. Once it is in an array you can update looping through the array.
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
add a comment |
If you set the names of the checkboxes toname="students"
PHP can store all the names in an array by using the list function. Once it is in an array you can update looping through the array.
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
add a comment |
If you set the names of the checkboxes toname="students"
PHP can store all the names in an array by using the list function. Once it is in an array you can update looping through the array.
If you set the names of the checkboxes toname="students"
PHP can store all the names in an array by using the list function. Once it is in an array you can update looping through the array.
answered Nov 19 '18 at 20:43
Dan W.Dan W.
686
686
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
add a comment |
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
do I need to declare that before hand? I tried adding it and doing a var_dump to check results but only got errors
– Matt
Nov 19 '18 at 20:50
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
@Matt You shouldn't need to declare it. If you post the errors I may be able to figure out what's wrong.
– Dan W.
Nov 20 '18 at 3:45
add a comment |