- php stop form from posting
- <form id = "form" action = "./?page=markandfeedback" method = "post">
- <br>
- Mark for:
- <INPUT id="stud" onkeypress="return isNumberKey(event)" type="text" name="stud" value="Enter Student Number">
- <input type="submit" value = 'Continue'>
- <?
- $studID = $_POST['stud'];
- $module2 = $_SESSION['module'];
- $ex = $_POST['exer'];
- $studerr = array();
- $sql = 'SELECT * FROM `student`, `modules` WHERE `studentID` = '.$studID.' AND `moduleCode` = '.$_SESSION['module'];
- $result = mysql_query ($sql);
- // echo $_SESSION['module'];
- if ($result == NULL) { // nothing found
- echo "the student id you entered is not in the database";
- }
- else {
- $_SESSION['student'] = $studID;
- Header("Location: http://www.whereever.com/"); // send the browser where you want
- exit();
- }
- ?>
- <input id="stud" onchange="checkStudentId(this)" />
- <script>
- function checkStudentId(inputElement) {
- var id = inputElement.value();
- $.ajax({
- url: "test.html",
- context: {id:id}
- }).done(function() {
- // Check the return result
- });
- }
- </script>
- <?
- if(isset($_POST['stud'])){
- $studID = $_POST['stud'];
- $module2 = $_SESSION['module'];
- $ex = $_POST['exer'];
- $studerr = array();
- $host="hostname";//your db host
- $user="user";//your db user
- $pass="pass";//your db pass
- $conn=mysql_connect($host,$user,$pass);
- $sql = 'SELECT * FROM `student`, `modules` WHERE `studentID` = '.$studID.' AND `moduleCode` = '.$_SESSION['module'];
- $result = mysql_query ($sql,$conn);
- if(mysql_num_rows($result)>0){//the id was found in the DB, do whatever here...
- echo $_SESSION['module'];
- $_SESSION['student'] = $studID;
- Header("Location: http://www.whereever.com/");//redirect to wherever
- $error=false;
- }
- else{//id was not found
- $error=true;}
- }//end of isset
- ?>
- <? if($error===true){?> <div> The id was not found.... </div> <?}?>
- <form id = "form" action = "<? echo $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>" method = "post">
- <br>
- Mark for:
- <INPUT id="stud" onkeypress="return isNumberKey(event)" type="text" name="stud" value="Enter Student Number">
- <input type="submit" value = 'Continue'>