Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. function submitForm(formId){
  5.  
  6. //var formData= $.(formId).serialize();
  7. $.ajax({
  8. url:'action/new-user.php',
  9. type:'POST',
  10. data:{
  11. user_name=$("#user_name").val(),
  12. password=$("#password").val();
  13. }
  14. suceess:function(response){
  15. alert(response);
  16. }
  17. });
  18. }
  19. </script>
  20. </head>
  21.  
  22. <body>
  23. <form onsubmit="submitForm('#myForm');" id='myForm'>
  24. User Name: <input type="text" name="user_name" id="user_name" />
  25. Password: <input type="text" name="password" id="password" />
  26. <input type="submit"/>
  27. </form>
  28. </body>
  29.  
  30. </html>
  31.  
  32. <?php include 'database.php';?>
  33.  
  34. <?php
  35. mysqli_query($connect,"create table login(User_name varchar(50) NOT NULL,Password varchar(50) NOT NULL)");
  36. $user_name=$_POST['user_name'];
  37. $password=$_POST['password'];
  38. if(empty($user_name)){
  39. $name_error="name is required";
  40. }
  41.  
  42. mysqli_query($connect,"Insert into login(User_name,Password) values('$user_name','$password')");
  43. if(mysqli_affected_rows($connect)>0){
  44. echo "<p>Credentials added</p>";
  45. echo "<a href='index.html'>Go back</a>";
  46. }else{
  47. echo "<p>Error</p>";
  48. echo mysqli_error($connect);
  49. }
  50. ?>
  51.  
  52. <?php
  53. $connect=mysqli_connect('localhost','root','','testdb');
  54. if(mysqli_connect_errno($connect)){
  55. echo 'failed to connect';
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement