Creazione Script Commenti In Php Da Zero
-
Salve a tutti, stò creando da zero un form dove ha il presupposto di lasciare un commento nel sito, ho creato 3 pagine
nella PRIMA: LASCIACOMMENTO.PHP<body><form method="post" action="vedicommenti.php">
<p>Username<input type="text" name="username"></p>
<p>Scrivi il tuo commento</p>
<p>
<textarea name="commento" cols="55" rows="12"></textarea>
<!--inserisci i parametri che preferisci--></p>
<p>
<input type="submit" value="Lascia commento"></p>
</form><p> </p>
</body>LA SECONDA: VEDICOMMENTI.PHP
<h1 align="center">COMMENTI</h1>
<?php
include "config.php";
$user=$_POST['username'];
$commento=$_POST['commento'];
//devi archiviare in database quindi creati la connessione e inserisci nella tabella
echo"messaggio inviato da: $user";
?>
<p>COMMENTO:
<?php
echo"$commento";
?>
</p>FINO A QUESTO PUNTO MI FUNZIONA, PERò QUANDO FACCIO UN NUOVO COMMENTO, IL COMMENTO PRECEDENTE SCOMPARE. IO VORREI CHE SI REGISTRASSE IN UN DATABASE, COME POSSO FARE? NN SONO MOLTO PRATICO AL LATO DB.
QUESTO è CONFIG.PHP:
<?php
$db_host = "XX.XXX.XXX.XX";
$db_user = "SqlXXXXXX;
$db_password = "1234567";
$db_name = "Sql1234567_4";$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
?>E NON RIESCO A FARLO FUNZIONARE ... DEVO CREARE UNA TABELLA IN .SQL? MI AIUTATE A CREARLA O QUALCHE DIRITTA DI QUELLE RELATIVE A QUESTO PROBLEMA!?
GRAZIE INFINITE A CHI MI POTRA' AIUTARE

-
Ho creato una tabella così ho fatto qualche errore?
questi sono i campi che mi sevono
ID, USERNAME, COMMENTO, DATACREATE TABLE COMMENTI(
id INT (5) UNSIGNED not null AUTO_INCREMENT,
USERNAME VARCHAR(20),
COMMENTO TEXT(20),
DATA DATETIME(20),
PRIMARY KEY (id)
)grazie di cuore a tutti

-
fai una query per inserire i messaggi nella tabella
TEXT(20) mi sa che non dovrebbe avere limite...
-
-
Hai letto come fare?
http://www.giorgiotave.it/guida_php/mysql_database.php -
si infatti questo: CREATE TABLE COMMENTI(
id INT (5) UNSIGNED not null AUTO_INCREMENT,
USERNAME VARCHAR(20),
COMMENTO TEXT(20),
DATA DATETIME(20),
PRIMARY KEY (id)
)
lL'HO CREATO GRAZIE AL POST DEL NOSTRO GIORGIO, MA COSA DEVO AGGIUNGERE O RIFARE, UNA QUERY?
COME SI FA?
SCUSA MA IO NN SONO PRATICO, MI AIUTERESTI A CAPIRE DI +? -
allora togli (20) da TEXT(20)
dopo per eseguire le query da php devi usare la funzione mysql_query
Esempio pratico:
mysql_query("INSERT INTO elenco (nome, ruolo, squadra)
VALUES(
'$a',
'$b',
'$c')"); -
al posto di TEXT(20) scrivi smalltext
$query = "INSERT INTO commenti (username, commento, data) VALUES ('$user', '$commento', '$data')"; $eseczione = mysql_query($query, $db); //PER LA DATA, PRIMA RICHIAMO LA FUNZIONE DATE: $data = date("D/F/Y")abbiamo risposto insieme

-
COSì?
TEXT mysql_query("INSERT INTO elenco (nome, ruolo, squadra)
VALUES(
'$a',
'$b',
'$c')");CREATE TABLE COMMENTI(
id INT (5) UNSIGNED not null AUTO_INCREMENT,
USERNAME VARCHAR(20),
COMMENTO TEXT mysql_query("INSERT INTO elenco (nome, ruolo, squadra)
VALUES(
'$a',
'$b',
'$c')");
DATA DATETIME(20),
PRIMARY KEY (id)
)QUESTO ? POI DEVO CREARE UN FILE SQL E IMPORTARLO NEL DATABASE?
-
-
no
CREATE TABLE COMMENTI( id INT (5) UNSIGNED not null AUTO_INCREMENT, USERNAME VARCHAR(20), COMMENTO TEXT(20), DATA DATETIME(20), PRIMARY KEY (id) )questo è quello che devi importare nel database mentre mysql_Query(... è la funzione che devi usare nel file php
-
quando importo il file sql mi da errore che devo fare?
CREATE TABLE COMMENTI(id INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,USERNAME VARCHAR( 20 ) ,
COMMENTO SMALLTEXT( 20 ) ,
DATA DATETIME( 20 ) ,
PRIMARY KEY ( id )
)
Messaggio di MySQL:
#1064 - 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 'SMALLTEXT(20),
DATA DATETIME(20),
PRIMARY KEY (id)
)' at line 4 -
CREATE TABLE COMMENTI(id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
USERNAME VARCHAR( 20 ) ,
COMMENTO TEXT,
DATA DATETIME ,
PRIMARY KEY ( id )
) -
-
Hai creato la tabella ora devi usare la funzione mysql_query() da php
PS non scrivere in maiuscolo perchè equivale ad urlare
-
-
ok, scusami..
quindi devo inserire$query = "INSERT INTO commenti (username, commento, data) VALUES ('$user', '$commento', '$data')";
$eseczione = mysql_query($query, $db);
//PER LA DATA, PRIMA RICHIAMO LA FUNZIONE DATE: $data = date("D/F/Y")Nel file .php?
-
mi da qesto errore
Errore
**query SQL:** $query = "INSERT INTO commenti (username, commento, data) VALUES ('$user', '$commento', '$data')"; **Messaggio di MySQL:**#1064 - 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 '$query = "INSERT INTO commenti (username, commento, data) VALUES ('$user', '$com' at line 1
-
questo è il file vedicommenti.php non sono sicuro di aver inserito la query in modo giusto
<?php
include "config.php";
$user=$_POST['username'];
$commento=$_POST['commento'];
//devi archiviare in database quindi creati la connessione e inserisci nella tabella
echo"messaggio inviato da: $user";
$query = "INSERT INTO commenti (username, commento, data) VALUES ('$user', '$commento', '$data')";
$esecuzione = mysql_query($query, $db);
//PER LA DATA, PRIMA RICHIAMO LA FUNZIONE DATE: $data = date("D/F/Y")
?>
<p>COMMENTO:
<?php
echo"$commento";
?> -
anche con questa query mi da errore
Errore
**query SQL:** mysql_query( "INSERT INTO elenco (username, commento, data) VALUES( '$username', '$commento', '$data')")
Messaggio di MySQL:
#1064 - 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 'mysql_query("INSERT INTO elenco (username, commento, data)
VALUES(
'$username'' at line 1
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi