Hi,
ich habe eine Frage zu einem INSERT INTO. Ich arbeite gerade an einem Stundenplan mit PHP.
Nun wähle ich die Stunden bei diesem Quellcode aus...
PHP-Code:
.<br>
<h2>Stundenplan für</h2>
<?php
$col1 = "#ffffff" ;
$col2 = "#C0C0C0";
echo "<table border=\"0\">";
?>
<form action = "./?p=std_add" method = "post">
<colgroup>
<col width="165"><col width="165"><col width="165"><col width="165"><col width="165">
</colgroup>
<tr bgcolor="#C0C0C0">
<th>Montag</th><th>Dienstag</th><th>Mittwoch</th><th>Donnerstag</th><th>Freitag</th>
</tr>
<?php
for ($j=0; $j<=9; $j++){
$color = ($color == $col1) ? $col2 : $col1;
echo"<tr bgcolor=\"$color\">";
for ($i=1; $i<=5; $i++){
echo"<td>\n";
$sql = 'SELECT LehrerID, Name FROM baptime_lehrer'; $query = mysql_query($sql);
echo "<p><select size='1' name=LehrerID[]'>";
while ($ds = mysql_fetch_object($query)){
echo '<option value="'.$ds->LehrerID.'">'.$ds->Name.'</option>';}
$sql = 'SELECT FachID, Bezeichnung FROM baptime_fach'; $query = mysql_query($sql);
echo "<p><select size='1' name='FachID[]'>";
while ($ds = mysql_fetch_object($query)){
echo '<option value="'.$ds->FachID.'">'.$ds->Bezeichnung.'</option>'; }
echo"</td>\n";
}
echo"</tr>\n";
}
echo "</table>";
?>
<input type="submit" name="Submit" value="Speichern"><br><br>
</form>
<?php
$sql = 'SELECT gruppe FROM groups'; $query = mysql_query($sql);
echo "<p><select size='1' name=gruppe[]'>";
while ($ds = mysql_fetch_object($query)){
echo '<option value="'.$ds->gruppe.'">'.$ds->gruppe.'</option>';}
?>
Anschließend füge ich die Daten in die Datenbank...
PHP-Code:
<?
include("../includes/db.inc.php");//Verbindung zur Datenbank herstellen
include("../includes/functions.inc.php");
$count = count( $_POST['LehrerID'] );
$sqlQuery = array();
for( $i = 0; $i < $count; $i++ )
{
$sqlQuery[$i] = ' INSERT INTO
`baptime_stundenverteilung`
(
`LehrerID`,
`FachID`,
`gruppe`
)
VALUES
(
'.$_POST['LehrerID'][$i].',
'.$_POST['FachID'][$i].',
'.$_POST['gruppe'][$i].'
)
';
if( !mysql_query( $sqlQuery[$i] ) )
{
echo mysql_error()."\n";
}
}
$sqlQuery = ''; // $sqlQuery leeren
?>
Er sagt immer Syntaxfehler bei Zeile 15 oder so. Wahrscheinlich liegt es daran, dass der letzte Wert "gruppe" ein varchar(16) ist, die beiden anderen IDs sind INT... wisst ihr, warum es nicht funktioniert?
Vielen Dank im Voraus