I have a problem with a if statement to determine whether the option box has the value "Choose Here", if it's not proceed to the following function inside the if statement. The $EnrollmentMonth
is working fine capturing the value from elsewhere.
<script>
function promptEnrollmentMonth () {
if (document.getElementById("add_product").value !== "Choose here") {
var month = prompt("Is this the correct month for this course/product?", "<?php echo $EnrollmentMonth; ?>");
if (month != null) {
window.location.href = "studentupdate.php?id=<?php echo $StudentID?>" + "&enrollmentmonth=" + month;
<?php
$EnrollmentMonth = $_GET['enrollmentmonth'];
$sql3 = "INSERT into enrollment (StudentID, ProductID, EnrollmentMonth) VALUES ($StudentID, $select1, $EnrollmentMonth)";
mysql_query($sql3);
?>
// Insert result if the prompt box does not return null.
}
} else {
document.write("Stuck here!");
}
}
</script>
<button type="submit" onclick="promptEnrollmentMonth();">Update</button>
<?php
$sql2 = 'SELECT * FROM product ORDER BY ProductID ASC';
$sql2 = "SELECT * FROM product WHERE ProductID NOT IN (SELECT ProductID from enrollment WHERE StudentID = '$StudentID') ORDER BY ProductID ASC";
$result_select = mysql_query($sql2);
$rows = array();
while ($row = mysql_fetch_array($result_select)) {
$rows[] = $row;
}
echo "<div class=\"spanstyle\">Add course/product:<select name='add_product'>";
echo "<option value='Choose here' selected>Choose here</option>";
foreach ($rows as $row) {
echo "<option value='" . $row['ProductID'] . "'>" . $row['ProductName'] . "</option>";
}
echo "</select></div>";
?>