PHP – MYSQL – Insert Records

I Records sono le righe della tabella.

Syntax:

INSERT INTO table_name
VALUES (value1, value2, value3,…)

or

INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)

<?php
// Create connection
// Statement: mysqli_connect(host,username,password,dbname)
// NOTICE: se lo script è installato nello stesso server del Data Base, host->localhost
$con=mysqli_connect("localhost","lucedigi_user","mypassword","lucedigi_testphp");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else
  {
  echo "Great! Connect to MySQL!";
  }
// Aggiungere nuovi record alle colonne - START
// Statement:
// INSERT INTO table_name (column1, column2, column3,...) 
// VALUES (value1, value2, value3,...)
mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin',35)");

mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire',33)");
echo "Great! New Record Inserted!"; 
// Aggiungere nuovi record alle colonne - END

mysqli_close($con); 
echo "Great! Connection Closed!"; 
?>

phpMyAdmin Dashboard:

mysql-0003