ciao ragazzi, ho un problema che non riesco a risolvereDevo inserire dei commenti nel mio database in una specifica tabella commenti dopo gli attributi sono:
id
testo
username(user dell'utente che ha commentato)
articolo(l'articolo che voglio commentare)
ho una pagina commenti.php che richiama l'id dell'articolo dalla pagina index e lo user dell'utente loggato, entrambi questi valori li passerò hidden e li inserirò nella tabella, ho fatto un form di inserimento ma mi esce questo errore
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1..
Vi posto il codice di commenti.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
//connessione al database e seleziono l'articolo da commentare
include "connessione.php";
$id=$_GET['art'];
$usern=$_GET['user'];
$query_searchnewart = "SELECT * from articolo where ID=$id";
$searchnewart = mysql_query($query_searchnewart) or die(mysql_error());
$row_searchnewart = mysql_fetch_assoc($searchnewart);
$totalRows_searchnewart = mysql_num_rows($searchnewart);
$query_user = "SELECT * FROM membro where username='$usern'";
$user = mysql_query($query_user) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
echo "
<FORM ACTION ='$_SERVER[PHP_SELF]' method='POST'>
<INPUT type='textarea' name='testo' maxlength='36' size='36' value='$testo'> (Solo numeri)</p>
<INPUT type='hidden' name='usern' maxlength='50' size='50' value='$usern'></p>
<INPUT type='hidden' name='articolo' maxlength='30' size='30' value='$id'></p>
<INPUT type='SUBMIT' value='Invia'>
<INPUT type='RESET' value='Cancella'>
</FORM></p>";
$testo=$_POST["testo"];
$usern=$_POST['usern'];
$id=$_POST['articolo'];
// INSERIMENTO
$stringa = "INSERT INTO commenti (id,testo,username,articolo ) VALUES ";
$stringa .= "( '','$testo','$usern','$id' )";
?>
<?php
if ( !mysql_query ( $stringa ) )
{
echo ( "ERRORE: nell' inserimento commenti");
exit();
}
else{
echo "commento inserito correttamente";
}
mysql_close( $conn );
?>
</body>
</html>
spero di avere una risposta grazie!