Il primo file include della variabili utili alla connessione e il secondo inserisce i dati nel database (includendo il primo file nella prima riga). Se l'operazione non va a buon fine viene intercettato l'errore e mostrato a video.
File connectionvar.php
<?php # Type="MYSQL" # HTTP="true" $hostname_localhost = "localhost"; $database_localhost = "dbname"; $username_localhost = "root"; $password_localhost = "password"; $con_localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR); ?>File insertdata.php
<?php require_once('Connections/connectionvar.php'); ?> <html> ... <!-- html here--> <?php $lastname = $_POST['lastname']; $name = $_POST['name']; mysql_select_db($database_localhost, $con_localhost); $sql = "insert into tbl_employee (name, lastname) values( '".trim($name)."','".trim($lastname)."')"; $result = mysql_query($sql,$con_localhost); if (!$result){ echo mysql_errno() . ": " . mysql_error() . "\n"; } else { ?> ... <!-- html here--> <?php mysql_close($con_localhost); ?> </html>