I am creating a scholarship application selection tool where students can select multiple scholarships to apply to. They review the list of scholarships and check off the ones they want to apply to. I need this data to insert into the same table. The ID is the scholarship ID and UID is the student ID. I am creating this in PHP using Dreamweaver. The following is what I have but, it is not working. Any suggestions would be great. Thanks
THE CODE:
mysql_select_db($database_connect, $connect);
$query_your_scholarships = "SELECT * FROM scholarships ORDER BY NAME ASC";
$your_scholarships = mysql_query($query_your_scholarships, $connect) or die(mysql_error());
$row_your_scholarships = mysql_fetch_assoc($your_scholarships);
$totalRows_your_scholarships = mysql_num_rows($your_scholarships);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$valuesSets = "";
for ($i=0; $i < count($ID); $i++) {
$valuesSets.="(".GetSQLValueString($UID[$i], "int").",".GetSQLValueString($ID[$i], "int")."),";
$valuesSets=substr($valuesSets,0,-1); // to remove last comma
$insertSQL = sprintf("INSERT INTO stu_schol (`UID`, `ID`) VALUES %s", $valuesSets);
mysql_select_db($database_connect, $connect);
if ($valuesSets <> "") {
// echo $insertSQL;
$Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
$insertGoTo = "main_page.php?UID=" . $_GET['UID'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}}
THE FORM:
<form method="POST" action="<?php echo $editFormAction; ?>" name="standardapps">
<input name="ID[]" type="checkbox" id="ID{}" value="<?php echo $row_your_scholarships['ID']; ?>" />
Add</label>
<input name="UID[]" type="hidden" id="UID{}" value="<?php echo $_GET['UID']; ?>" />
<input type="submit" class="btn" name="submit" id="submit" value="Update My Selections" />
</form>