The problem with what you want to do is that PHP doesn't execute with JavaScript. The PHP is server-side, so when calling update_student() from JavaScript doesn't run any of that PHP code you put in there, because all of that PHP code has already been run.
You are in essence trying to do something like this:
<SCRIPT>
class_no = 2;
<?php
for ($i = 1; $i <= 3; $i++) {
echo "if (class_no == $i) {";
echo " alert('$i');";
$class_numbers[] = $i;
echo "}";
}
foreach ($class_numbers as $class_number) {
echo "alert($class_number);";
}
?>
</SCRIPT>
The problem with that code is that this is what the browser will get!
<SCRIPT>
class_no = 2;
if (class_no == 1) {
alert('1');
}
if (class_no == 2) {
alert('2');
}
if (class_no == 3) {
alert('3');
}
alert('1');
alert('2');
alert('3');
</SCRIPT>
That is because all PHP code is executed before anything goes to the user's browser. PHP is server-side, not client-side. You cannot mix the two together!! A bad analogy is that you are trying to listen to a CD on your computer, but the CD is sitting in your car. I know that analogy doesn't really make sense... but the point is: You can't listen to a CD on your computer when the CD is sitting in your car. You have to have the CD in your computer to listen to it in your computer.
You can't use an if() statement in JavaScript to conditionally executed some PHP code, because the PHP code is executed before the JavaScript code is ever seen by the browser.
If you right click on your page, and click on "View Source", you will see what I am talking about. The alerts are hardcoded in the HTML page. When you view source on your computer, you don't see any PHP code in it, that's be cause it is server-side.
I hope you are understanding what I am saying... There is a way to do what you are wanting to do, but you're trying to do it in a way that is not possible.
Hope that helps,
-Percy