Hello All!
I'm a complete newb in PHP/MySQL/Apache and I'm volunteering for a non-profit organization, I had expected to spend a couple of hours on the site and I'm about 15 hours in already.
I'm trying to create an attendance sheet and post it to an event table. The code to create the 'form' is:
<?php
$connect = mysql_connect("localhost","un","pw");
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cha", $connect);
$query = mysql_query("SELECT pkid, concat(firstname, ' ', lastname) as name FROM people
order by name" ) or die (mysql_error());
echo "<html>";
echo "<body>";
echo "<form action='/insertattend.php/' method='post'>";
echo "<TABLE BORDER='1' ALIGN='CENTER' CELLPADDING='2' CELLSPACING='2' WIDTH='50%'>
<tr>
<th></th>
<th>Student</th>
<th>Attended</th>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr><td>";
echo '<input type="hidden" name="pkid[]" value="' . $row['pkid'] . '" >';
echo "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<TD><select name='attended[]'><option value=1>Yes</option><option value=0>No</option></select></TD></TR>";
}
echo "</table>
<TABLE BORDER='0' ALIGN='CENTER' CELLPADDING='4' CELLSPACING='4' WIDTH='50%'>
<TR><TD ALIGN='CENTER'><input type='submit' value= 'Submit Attendance' /></TD></TABLE></form></body></html>";
?>
Then the post script is:
<?php
$connect = mysql_connect("localhost","un","pw");
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cha", $connect);
$type = $_POST["pkid"];
foreach($type as $key => $value){
echo $key.": ".$value;
}
?>
This gives me the following: 0: 11: 102: 93: 154: 355: 116: 47: 38: 259: 1310: 3411: 2412: 613: 3614: 2615: 516: 717: 1618: 819: 1420: 1221: 3722: 2723: 1724: 1825: 2826: 3827: 2928: 1929: 3930: 4031: 2032: 3033: 4134: 3135: 2136: 2237: 3238: 4239: 3340: 2341: 2
I'm not sure what those values are. I would expect the list of pkid's: 1:2:3:4:5:6... as there are only 45 children in the database.
I also need to insert other values i.e. whether or not they attended (yes or no), what program they're in will be a hidden value passed from the form as well as the site and lesson code.
Is this possible in PHP?
I truly appreciate any help and this functionality for the np-org I'm volunteering for will save massive amounts of time.
JP