Help with insert into database code
Posted: Tue Jan 12, 2010 10:47 pm
Hello All,
I'm trying to create a simple "Take Attendance" page. I've listed the HTMl code and the PHP code that is supposed to dump everything into the database. My problem, is that the code is only dumping the last name on the check list into the datbase, and the function I'm trying to use isn't generating the date. Of course, all this is code I found on forums and I'm just piecing it together since I'm a newbie when it comes to PHP, so don't assume that I know what I'm doing, and the code that I'm listing is almost as is, except I have the form calling the PHP code instead of putting it all in one form. Please let me know if you have any suggestions, school starts next week, and thanks in advance!
I'm trying to create a simple "Take Attendance" page. I've listed the HTMl code and the PHP code that is supposed to dump everything into the database. My problem, is that the code is only dumping the last name on the check list into the datbase, and the function I'm trying to use isn't generating the date. Of course, all this is code I found on forums and I'm just piecing it together since I'm a newbie when it comes to PHP, so don't assume that I know what I'm doing, and the code that I'm listing is almost as is, except I have the form calling the PHP code instead of putting it all in one form. Please let me know if you have any suggestions, school starts next week, and thanks in advance!
Code: Select all
<form action="script.php" method="POST">
Student #1 <input type="checkbox" name="student[]" value="999999"><br />
Student #2 <input type="checkbox" name="student[]" value="666666">
<br/>
<INPUT TYPE="SUBMIT" VALUE="Submit" >
</FORM>
<?php
$host = 'xxxxxxxxxxxx';
$user = 'xxxxxxxxxxxx';
$pass = 'xxxxxxxxxxxx';
$db = 'xxxxxxxxxxxx';
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$classdate = strtotime($_POST['date']);
foreach($_POST['student'] as $oasis_id);
$query = "INSERT INTO xxxxxxxxxxxx (oasis_id, classdate)".
"values ('$oasis_id','$classdate')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
?>