4 files:
install.php
Codice PHP:
<?php
// Connessione al Server MySQL
$connection = @MySQL_connect("localhost","root","")
// Eventuale messaggio di errore
or die("Connessione non riuscita");
// Creo il DataBase 'simplenews'
$sql = "CREATE DATABASE `simplenews`;";
// // Eseguo i comandi citati in precedenza
@MySQL_query("$sql")
// Se la creazione del DataBase non va a buon fine, messaggio di errore
or die("Errore durante la creazione del DataBase");
// Creo la tabella 'news'
$sql = "CREATE TABLE `simplenews`.`news` (`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `title` VARCHAR(80) NOT NULL, `text` TEXT NOT NULL) ENGINE = MyISAM;";
// Eseguo i comandi citati in precedenza
@MySQL_query("$sql")
// Se la creazione della tabella non va a buon fine, messaggio di errore
or die("Errore durante l'Installazione");
?>
insert.html
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inserisci News</title>
</head>
<body>
<form method="post" action="insert.php">
Titolo: <input type="text" width="317" name="title" />
News: <textarea rows="5" cols="50" name="text"></textarea>
<input type="submit" value="Inserisci News" />
</form>
</body>
</html>
insert.php
Codice PHP:
<?php
// Richiamo il file della connessione al DataBase
require_once("connection.php");
// Inserisco la news nella tabella 'news' contenuta nel Database 'simplenews'
$sql = "INSERT INTO `news` (`ID`, `title`, `text`) VALUES (NULL, '$title', '$text');";
// Eseguo i comandi citati in precedenza
@MySQL_query("$sql")
// Se l'inserimento della news non è andato a buon fine
or die("Errore durante l'inserimento della News");
?>
connection.php
Codice PHP:
<?php
// Connessione al Server MySQL
$connection = @MySQL_connect("localhost","root","")
// Eventuale messaggio di errore
or die("Connessione non riuscita");
// Connessione al DataBase
@MySQL_select_db("simplenews",$connection)
// Eventuale messaggio di errore
or die("Database non trovato");
?>
Il problema è il seguente:
Notice: Undefined variable: title in C:\Program Files\EasyPHP3.1\www\simplenews\insert.php on line 5
Notice: Undefined variable: text in C:\Program Files\EasyPHP3.1\www\simplenews\insert.php on line 5
La versione di PHP utilizzata è il PHP 6 se non erro...
Risposte brevi e concise senza critiche possibilmente con codice corretto (mi pare di non chiedere la luna)
Grazie in anticipo.