Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <form action="form.php" method="post">
  2. First name:<br/>
  3. <input type="text" id="fname" name="fname">
  4. <br/>
  5. Last name:<br/>
  6. <input type="text" id="lname" name="lname">
  7. <br/>
  8. Mobile:<br/>
  9. <input type="text" id="mobile" name="mobile">
  10. <br/>
  11. <input type="submit" value="Submit">
  12. </form>
  13.  
  14. <?php
  15. $servername = "localhost";
  16. $username = "database1";
  17. $password = "xxxxxxxx";
  18. $dbname = "database1";
  19.  
  20.  
  21. $servernameS = "localhost";
  22. $usernameS = "database2";
  23. $passwordS = "xxxxxxxx";
  24. $dbnameS = "database2";
  25.  
  26. // Create connection
  27. $conn = new mysqli($servername, $username, $password, $dbname);
  28. $connS = new mysqli($servernameS, $usernameS, $passwordS, $dbnameS);
  29.  
  30. // Check connection
  31. if ($conn->connect_error) {
  32. die("Connection failed: " . $conn->connect_error);
  33. }
  34. if ($connS->connect_error) {
  35. die("Connection failed: " . $connS->connect_error);
  36. }
  37.  
  38. //escape variables for security
  39. $fname = mysqli_real_escape_string($conn, $_POST['fname']);
  40. $lname = mysqli_real_escape_string($conn, $_POST['lname']);
  41. $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
  42.  
  43. $sql = "INSERT INTO mytable (fname,lname,mobile)
  44. VALUES ('$fname','$lname','$mobile')";
  45.  
  46. if ($conn->query($sql) === TRUE) {
  47. echo "Successfully Saved";
  48.  
  49. } else {
  50. echo "Error: Go back and Try Again ! " . $sql . "<br>" . $conn->error;
  51. }
  52.  
  53. if ($connS->query($sql) === TRUE) {
  54. echo "Successfully Saved";
  55.  
  56. } else {
  57. echo "Error: Go back and Try Again ! " . $sql . "<br>" . $connS->error;
  58. }
  59. $conn->close();
  60. $connS->close();
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement