Insert to MySQL from a Post array
Posted: Tue Jul 08, 2008 10:43 am
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:
Then the post script is:
This only gives me the following 0:2
It doesn't give me the array.
What I really need to do is create a record within the event table for each child that was at the lesson. I can't even seem to view the $_POST array let alone insert it into mySQL. I'm a wiz at SQL but this PHP stuff isn't my bag.
I truly appreciate any help and this functionality for the np-org I'm volunteering for will save massive amounts of time.
JP
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:
Code: Select all
<?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:
Code: Select all
<?php
$connect = mysql_connect("localhost","un","pw");
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cha", $connect);
$type = array($_POST["pkid"]);
foreach($type as $key => $value){
echo $key.": ".$value;
}
?>It doesn't give me the array.
What I really need to do is create a record within the event table for each child that was at the lesson. I can't even seem to view the $_POST array let alone insert it into mySQL. I'm a wiz at SQL but this PHP stuff isn't my bag.
I truly appreciate any help and this functionality for the np-org I'm volunteering for will save massive amounts of time.
JP