Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 17th, 2012  |  syntax: None  |  size: 2.29 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. php stop form from posting
  2. <form id = "form" action = "./?page=markandfeedback" method = "post">
  3.  
  4.     <br>
  5.     Mark for:
  6. <INPUT id="stud" onkeypress="return isNumberKey(event)" type="text" name="stud"  value="Enter Student Number">
  7. <input type="submit" value = 'Continue'>
  8. <?
  9.  
  10. $studID = $_POST['stud'];
  11. $module2 = $_SESSION['module'];
  12. $ex = $_POST['exer'];
  13. $studerr = array();
  14.  
  15. $sql = 'SELECT * FROM `student`, `modules` WHERE `studentID` = '.$studID.' AND `moduleCode` = '.$_SESSION['module'];
  16. $result = mysql_query ($sql);
  17. //    echo $_SESSION['module'];
  18.  
  19. if ($result == NULL) { // nothing found
  20. echo "the student id you entered is not in the database";
  21. }
  22. else {
  23.  
  24.  
  25. $_SESSION['student'] = $studID;
  26.  
  27. Header("Location: http://www.whereever.com/"); // send the browser where you want
  28. exit();
  29. }
  30. ?>
  31.        
  32. <input id="stud" onchange="checkStudentId(this)" />
  33.  
  34. <script>
  35. function checkStudentId(inputElement) {
  36.  var id = inputElement.value();
  37.  
  38.   $.ajax({
  39.     url: "test.html",
  40.     context: {id:id}
  41.   }).done(function() {
  42.     // Check the return result
  43.   });
  44. }
  45. </script>
  46.        
  47. <?
  48.         if(isset($_POST['stud'])){
  49.             $studID = $_POST['stud'];
  50.             $module2 = $_SESSION['module'];
  51.             $ex = $_POST['exer'];
  52.             $studerr = array();
  53.     $host="hostname";//your db host
  54.     $user="user";//your db user
  55.     $pass="pass";//your db pass
  56.     $conn=mysql_connect($host,$user,$pass);
  57.  
  58.             $sql = 'SELECT * FROM `student`, `modules` WHERE `studentID` = '.$studID.' AND `moduleCode` = '.$_SESSION['module'];
  59.             $result = mysql_query ($sql,$conn);
  60.  
  61.          if(mysql_num_rows($result)>0){//the id was found in the DB, do whatever here...
  62.  
  63.         echo $_SESSION['module'];
  64.  
  65.         $_SESSION['student'] = $studID;
  66.  
  67.     Header("Location: http://www.whereever.com/");//redirect to wherever
  68.         $error=false;
  69.         }
  70.  
  71.         else{//id was not found
  72. $error=true;}
  73.  
  74.  
  75.  
  76.         }//end of isset
  77.         ?>
  78.  
  79.  
  80.  
  81.         <? if($error===true){?> <div> The id was not found.... </div> <?}?>
  82.         <form id = "form" action = "<? echo $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>" method = "post">
  83.  
  84.                 <br>
  85.                 Mark for:
  86.         <INPUT id="stud" onkeypress="return isNumberKey(event)" type="text" name="stud" value="Enter Student Number">
  87.         <input type="submit" value = 'Continue'>