Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. function saveUserInfo(userName, userEmail, optedIn, currentUser, catDog, otherBrand)
  2. {
  3. if(optedIn === "Yes")
  4. {
  5. finalAnswers = userName + "yes" + "~" + userEmail + "~" + optedIn + "~" + currentUser + "~" + catDog + "~" + otherBrand + "~";
  6. }else{
  7. finalAnswers = userName + "no" + "~" + userEmail + "~" + optedIn + "~" + currentUser + "~" + catDog + "~" + otherBrand + "~";
  8. // finalAnswers = userName + "~" + userEmail + "~0" + optedIn + "~1" + currentUser + "~2" + catDog + "~3" + otherBrand + "~4";
  9. }
  10.  
  11. try
  12. {
  13. $.ajax({
  14. url: surveyServer + finalAnswers,
  15. type: 'post',
  16. success: function(evt){
  17. console.log('success saving ' + finalAnswers);
  18. }
  19. });
  20. }
  21. catch(err)
  22. {
  23. alert(err.message);
  24.  
  25. }
  26. }
  27.  
  28.  
  29. function saveUser()
  30. {
  31. $('.wrapper').find("#userEmail").blur();
  32. if (($('#userName').val().length > 0) && ($('#userEmail').val().length > 0))
  33. {
  34. var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+.)+[A-Z]{2,4}$/i
  35. var valueToTest = $('#userEmail').val();
  36. if (testEmail.test(valueToTest))
  37. {
  38. //pass
  39. saveUserInfo($('#userName').val(), $('#userEmail').val(), $('#optedIn').val(), $('#currentUser').val(), $('#catDog').val(), $('#otherBrand').val());
  40. $('.wrapper').slick('slickNext');
  41. } else {
  42. // Do whatever if it fails.
  43. alert("Please enter a valid email address.");
  44. $('.wrapper').find("#userEmail").focus();
  45. }
  46.  
  47. }else{
  48. alert("Please enter your name and email address then click Submit.");
  49. $('.wrapper').find("#userName").focus();
  50. }
  51. }
  52.  
  53. if (isset($_GET['user']))
  54. {
  55. try
  56. {
  57. $dbh = new PDO('mysql:host=localhost; dbname=bp1234', 'bp1234','bp1234');
  58.  
  59.  
  60. $userAnswerArray = explode("~", $_GET['user']);
  61.  
  62. $stmt = $dbh->prepare("INSERT INTO bpQuiz (userName, userEmail, optedIn, currentUser, catDog, otherBrand) VALUES (:userName, :userEmail, :optedIn, :currentUser, :catDog, :otherBrand)");
  63.  
  64. $stmt->bindParam(':userName', $userName);
  65. $stmt->bindParam(':userEmail', $userEmail);
  66. $stmt->bindParam(':optedIn', $userOption);
  67. $stmt->bindParam(':currentUser', $currentUser);
  68. $stmt->bindParam(':catDog', $catDog);
  69. $stmt->bindParam(':otherBrand', $otherBrand);
  70.  
  71. // insert value
  72. $userName = $userAnswerArray[0];
  73. $userEmail = $userAnswerArray[1];
  74. $userOption = $userAnswerArray[2];
  75. $currentUser = $userAnswerArray[3];
  76. $catDog = $userAnswerArray[4];
  77. $otherBrand = $userAnswerArray[5];
  78. $stmt->execute();
  79.  
  80. }
  81.  
  82. catch (PDOException $e)
  83. {
  84. echo 'ERROR: ' . $e->getMessage();
  85. }
  86.  
  87. }
  88. else
  89. {
  90. echo "no querystring...";
  91. }
  92.  
  93. <input type="text" class="contactFormInputBox" name="userName" id="userName"/>
  94. <input type="text" class="contactFormInputBox" name="userEmail" id="userEmail"/>
  95. <input type="checkbox" name="optedIn" id="optedIn" value="Yes">
  96. <input type="radio" name="currentUser" value="1" id="currentUser">Yes
  97. <input type="radio" name="currentUser" value="0" id="currentUser">No
  98. <input type="radio" name="catDog" value="cat" id="catDog">Cat
  99. <input type="radio" name="catDog" value="dog" id="catDog">Dog
  100. <input type="radio" name="catDog" value="both" id="catDog">Both
  101. </div>
  102. <div class="surveyOptions" id="Q2-b">
  103. <input type="text" class="contactFormInputBox" name="otherBrand" id="otherBrand"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement