Guest User

Untitled

a guest
Feb 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>db1 test</title>
  4. </head>
  5. <body>
  6. <form id="myForm" action="userInfo.php" method="post">
  7. Username: <input type="text" name="username" /><br />
  8. Name: <input type="text" name="name" /><br />
  9. Favourite Number: <input type="text" name="favouritenumber" /><br />
  10. <button id="sub">Save</button>
  11. </form>
  12.  
  13. <span id="result"></span>
  14.  
  15. <script src="/script/jquery-1.8.1.min.js" type="text/javascript"></script>
  16. <script src="/script/my_script.js" type="text/javascript"></script>
  17. </body>
  18. </html>
  19.  
  20. <?php
  21. $host = "localhost";
  22. $port = "8889";
  23. $servername = "$host:$port";
  24. $username = "forest";
  25. $password = "";
  26. $db = "db1";
  27. // Create connection
  28. $conn = new mysqli_connect($servername, $username, $password, $db);
  29. // Check connection
  30. if ($conn - > connect_error) {
  31. die("Connection failed: ".$conn - > connect_error);
  32. }
  33. ?>
  34.  
  35. <?php
  36. include_once "/includes/db1.php";
  37. $username = $_POST['username'];
  38. $name = $_POST['name'];
  39. $favouritenumber = $_POST['favouritenumber'];
  40. if(mysqli_query("INSERT INTO user(username,name,favouritenumber) VALUES ('$username', '$name', '$favouritenumber')"))
  41. echo "Successfully Inserted";
  42. //echo "<a href='login_success.php'>Back to main page</a>";
  43.  
  44. else {
  45. echo "ERROR not entered";
  46. }
  47. // close connection
  48. mysqli_close();
  49.  
  50. [1]: https://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-mysql-num-rows-etc
Add Comment
Please, Sign In to add comment