nstruth2

Main Page

Jul 14th, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 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.                 $('#targetLegit').load('showProfileData.php');
  36.             }
  37.             else if(dataResult.statusCode==201){
  38.                 alert("Error occured !");
  39.             }
  40.            
  41.        
  42.     }
  43.  
  44.     });
  45. });
  46. });
  47. </script>
  48. <?php
  49. session_start();
  50.   if(!isset($_SESSION['user_id'])){
  51.         echo "You're not logged in<br>";
  52.         echo <<<EOT
  53. <a href="login2.php"><img src="loginicon.png"></a>
  54. </a><br>
  55. <a href="register2.php"><img src="RegisterButton.png"></a>
  56. </p>
  57. EOT;
  58.         exit;
  59.     } else {
  60.                 echo <<<EOT
  61.         <p> FORUM CODE HERE </p>
  62. <div style="margin: auto;width: 60%;">
  63.     <div class="alert alert-success alert-dismissible" id="success" style="display:none;">
  64.       <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
  65.     </div>
  66.     <form id="fupForm" name="form1" method="post">
  67.         <div class="form-group">
  68.             <label for="profilePageName">Name:</label>
  69.             <input type="text" class="form-control" id="profilePageName" placeholder="Name" name="profilePageName">
  70.         </div>
  71. <div>
  72.   <p><label for="aboutMeText">User Submitted Data</label></p>
  73.   <textarea id="aboutMeText" name="aboutMeText" rows="50" cols="100"></textarea>
  74. </div>
  75.         <input type="button" name="save" class="btn btn-primary btn-lg" value="Save to Database" id="butsave">
  76.     </form>
  77. </div>
  78. </body>
  79. EOT;
  80.    echo "Yo you're logged in";
  81.     }
  82. ?>
  83.       <p>Log-out icon on a styled link button:
  84.         <a href="logout2.php" class="btn btn-info btn-lg">
  85.           <span class="glyphicon glyphicon-log-out"></span> Log Out
  86.         </a>
  87.       </p>
  88.  
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment