nstruth2

Untitled

Jul 14th, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Insert data in MySQL database using Ajax</title>
  5.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  6.     <link rel="stylesheet" type="text/css" href="mystyle.css">
  7.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  8.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. </head>
  10. <body>
  11. <div id="targetLegit"> </div>
  12. <p id="target">
  13. </p>    
  14. <script>
  15. $(document).ready(function() {
  16. <!--$('#targetLegit').load('showProfileData.php');-->
  17. $('#butsave').on('click', function() {
  18. let profilePageName = $('#profilePageName').val();
  19. let aboutMeText = $('#aboutMeText').val();
  20.     $.ajax({
  21.         url: "saveProfileData.php",
  22.         type: "POST",
  23.         data: {
  24.         profilePageName,
  25.         aboutMeText,
  26.         },
  27.         cache: false,
  28.         success: function(dataResult){
  29.             dataResult = JSON.parse(dataResult);
  30.             if(dataResult.statusCode==200){
  31.                 $("#butsave").removeAttr("disabled");
  32.                 $('#fupForm').find('input:text').val('');
  33.                 $("#success").show();
  34.                 $('#success').html('Data added successfully !');    
  35.             }
  36.             else if(dataResult.statusCode==201){
  37.                 alert("Error occured !");
  38.             }
  39.            
  40.        
  41.     }
  42.  
  43.     });
  44. });
  45.  
  46. $('#butsave').on('click', function() {
  47. let profilePageName = $('#profilePageName').val();
  48. let aboutMeText = $('#aboutMeText').val();
  49.     $.ajax({
  50.         url: "showProfileData.php",
  51.         type: "POST",
  52.         data: {
  53.         profilePageName,
  54.         aboutMeText,
  55.         },
  56.         cache: false,
  57.         success: function(dataResult){
  58.             dataResult = JSON.parse(dataResult);
  59.             if(dataResult.statusCode==200){
  60.                 $("#butsave").removeAttr("disabled");
  61.                 $('#fupForm').find('input:text').val('');
  62.                 $("#success").show();  
  63.                 $('#targetLegit').load('showProfileData.php');
  64.             }
  65.             else if(dataResult.statusCode==201){
  66.                 alert("Error occured !");
  67.             }
  68.            
  69.        
  70.     }
  71.  
  72.     });
  73. });
  74.  
  75. });
  76. </script>
  77. <?php
  78. session_start();
  79.   if(!isset($_SESSION['user_id'])){
  80.         echo "You're not logged in<br>";
  81.         echo <<<EOT
  82. <a href="login2.php"><img src="loginicon.png"></a>
  83. </a><br>
  84. <a href="register2.php"><img src="RegisterButton.png"></a>
  85. </p>
  86. EOT;
  87.         exit;
  88.     } else {
  89.                 echo <<<EOT
  90.         <p> FORUM CODE HERE </p>
  91. <div style="margin: auto;width: 60%;">
  92.     <div class="alert alert-success alert-dismissible" id="success" style="display:none;">
  93.       <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
  94.     </div>
  95.     <form id="fupForm" name="form1" method="post">
  96.         <div class="form-group">
  97.             <label for="profilePageName">Name:</label>
  98.             <input type="text" class="form-control" id="profilePageName" placeholder="Name" name="profilePageName">
  99.         </div>
  100. <div>
  101.   <p><label for="aboutMeText">User Submitted Data</label></p>
  102.   <textarea id="aboutMeText" name="aboutMeText" rows="50" cols="100"></textarea>
  103. </div>
  104.         <input type="button" name="save" class="btn btn-primary btn-lg" value="Save to Database" id="butsave">
  105.     </form>
  106. </div>
  107. </body>
  108. EOT;
  109.    echo "Yo you're logged in";
  110.     }
  111. ?>
  112.       <p>Log-out icon on a styled link button:
  113.         <a href="logout2.php" class="btn btn-info btn-lg">
  114.           <span class="glyphicon glyphicon-log-out"></span> Log Out
  115.         </a>
  116.       </p>
  117.  
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment