×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Lee Laing
Added: Apr 5, 2018 4:54 AM
Modified: Apr 11, 2018 12:38 PM
Views: 1
Tags: no tags
Inserts new record line of data...No form used here.
  1. <?php
  2. $dbservername = "localhost";
  3. $dbusername = "root";
  4. $dbpassword = "password";
  5. $dbname = "spectrumBusiness";
  6. $dbport = "3306";
  7. $dbsocket = "/tmp/mysql.sock";
  8.  
  9. // Create connection
  10. $conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname, $dbport, $dbsocket);
  11.  
  12. // Check connection
  13. if ($conn->connect_error) {
  14.     die("Connection failed: " . $conn->connect_error);
  15.  
  16. //echo "Connected successfully"
  17. }
  18. $sql = "INSERT INTO tbl_sample (first_name, last_name, age)
  19. VALUES ('John', 'Doe', '99')";
  20.  
  21. if ($conn->query($sql) === TRUE) {
  22.     echo "New record created successfully";
  23. } else {
  24.     echo "Error: " . $sql . "<br>" . $conn->error;
  25. }
  26.  
  27. $conn->close();
  28. ?>