Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <form action="page2.php" method="post">
  2. Question 2: Your age ?<br> <input type = "radio" name="q2" value="a"> 15-<br>
  3. <input type = "radio" name="q2" value ="b"> 15-25<br>
  4. <input type = "radio" name="q2" value ="c"> 25-35<br>
  5. <input type = "radio" name="q2" value ="d"> 35+<br>
  6. </form>
  7. <a href="page2.php">Submit</a>
  8.  
  9. <?php
  10. $q2 = $_POST['q2'];
  11. Echo $q2;
  12. ?>
  13.  
  14. Notice: Undefined index: q2 in D:XAMPPhtdocspage2.php
  15.  
  16. <form action="page2.php" method="post">
  17. Question 2: Your age ?<br> <input type = "radio" name="q2" value="a"> 15-<br>
  18. <input type = "radio" name="q2" value ="b"> 15-25<br>
  19. <input type = "radio" name="q2" value ="c"> 25-35<br>
  20. <input type = "radio" name="q2" value ="d"> 35+<br>
  21. <input type='submit' value='Submit' />
  22. </form>
  23.  
  24. <input type = "radio" name="q2" value ="d"> 35+<br>
  25. <!-- add the submit button inside the form -->
  26. <input type="submit" name="submit">
  27. </form>
  28.  
  29. <?php
  30. //always use isset before checking for POST variables
  31. if(isset($_POST['submit']){
  32. $q2 = $_POST['q2'];
  33. echo $q2;
  34. }
  35. ?>
  36.  
  37. You have already written in form action
  38.  
  39. no need of this <a href="page2.php">Submit</a>
  40.  
  41. <input type="button" id="submit" name="submit" value="Submit"/>
  42. write this line before </form> tag close instead of this line
  43. <a href="page2.php">Submit</a>
  44.  
  45. <form action="page2.php" method="post">
  46. Question 2: Your age ?<br>
  47. <input type = "radio" name="q2" value="a"> 15-<br>
  48. <input type = "radio" name="q2" value ="b"> 15-25<br>
  49. <input type = "radio" name="q2" value ="c"> 25-35<br>
  50. <input type = "radio" name="q2" value ="d"> 35+<br>
  51. </form>
  52. <a href="page2.php">Submit</a>
  53.  
  54. <?php
  55. $q2 = $_POST['q2'];
  56. var_dump($q2);
  57. echo $q2;
  58. ?>
  59.  
  60. <form action="page2.php" method="post">
  61. Question 2: Your age ?<br>
  62. <input type = "radio" name="q2" value="a"> 15-<br>
  63. <input type = "radio" name="q2" value ="b"> 15-25<br>
  64. <input type = "radio" name="q2" value ="c"> 25-35<br>
  65. <input type = "radio" name="q2" value ="d"> 35+<br>
  66. <input type='submit' value='Submit' />
  67. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement