Questa è una vecchia versione del documento!
il casino è che dalla debian 9 è cambiata la versione di default del php che dalla 5 è passata alla 7.
Naturalmente su apache il php è caricato di default e per vedere le impostazioni del php.ini possiamo creare un file da mettere in /var/www/html ad esempio info.php
<?php
phpinfo();
?>
e vedere così com'è la situazione
ho capito che se si vuole creare un database nuovo per costruire qualcosa e inserire i dati ad esempio una pagina web, è bene dare ad un utente nuovo specifico per quel database i diritti per fare gli inserimenti e usare poi quell'utente da php.
quindi creiamo il database da riga di comando mariadb
create database prova;
poi creare tabelle
e qui dovro mettere il codice\\
poi creare l'utente specifico:
grant all privileges on database.* to 'nomeutentespecifico'@'localhost' identified by 'passwordutente';
altro file:
<html> <head> </head> <body> <?php $dbname = 'tato'; $dbuser = 'tato'; $dbpass = 'tatone'; $dbhost = 'localhost'; $link = new mysqli($dbhost, $dbuser, $dbpass, $dbname) ; // Check connection if ($link->connect_error) { die("Connection failed: " . $link->connect_error); } //mysqli_select_db($dbname) //or die("Could not open the db '$dbname'"); //$name = $_POST['name']; //$address = $_POST['address']; // $toinsert = "INSERT INTO anagrafica (name, address) VALUES ('$name','$address')"; $sql = "INSERT INTO anagrafica (name, address) VALUES ('".$_POST["name"]."','".$_POST["address"]."')"; if (mysqli_query($link, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "" . mysqli_error($link); } $link->close(); ?> test </body> </html>
form html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>PAGINA CARICAMENTO DATI</title> </head> <body> <table border="0"> <tr> <td align="center">Inserisci i dati richiesti</td> </tr> <tr> <td> <table> <form method="post" action="creadiretto.php"> <tr> <td>Nome</td> <td><input type="text" name="name" size="20"> </td> </tr> <tr> <td>Indirizzo</td> <td><input type="text" name="address" size="40"> </td> </tr> <tr> <td></td> <td align="right"><input type="submit" name="submit" value="Sent"></td> </tr> </form> </table> </td> </tr> </table> </body> </html>