stavo cercando di fare una sezione per le news per il mio sito e ho dei problemi con il seguente codice in php. In questa pagina dovrebbe inserirmi nel database il testo di una form.
Codice: Seleziona tutto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link rel=stylesheet href="style.css" type="text/css">
<TITLE>...sezione news...</TITLE>
</head>
<body>
<table align="center" width="750" bgcolor="White" border="1" cellspacing="0" cellpadding="0"><tr><TD>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<label>Inserisci la notizia: <br/>
<textarea name="newstext" rows="20" cols="65" ></textarea>
</label>
<input type="submit" value="invia" />
</form>
<?php
if (isset($_POST['newstext'])) {
//Mi connetto al database
$dbconn = @mysql_connect('localhost','root','miapassword');
if (!dbconn) {
echo '<p>Unable to connect to the database server at this time.</p>');
exit();
}
//Seleziono il database con cui lavorare
mysql_select_db('news',$dbconn);
if (!@mysql_select_db('news')) {
exit('<p>Unable to locate the news database at this time.<p>');
}
$newstext = $_POST['newstext'];
$query = "Insert into table_news set testo = '$newstext', data = CURDATE()";
if (@mysql_query($query)) {
echo '<p> Your news has been added. </p>';
}else {
echo '<p> Error adding submitted news: ' . mysql_error() . '</p>';
}
}
?></TD></tr></table>
</body>
</html>Ovviamente php e mysql girano correttamente sulla macchina e apache è avviato. Il database news e la tabella table_news sono state create. Dove sbaglio? Non mi sembra ci siano errori nel codice. Ciao.

