in my general database I have 5 database
- information schema
- mysql
- performance schema
- phpadmin
- test
- wordpress
the base I use is test, inside I have my table commenti that contains 3 fields which are
- nome varchar (15)
- varchar commentary (255)
- date date
on my main page I have a text box and a comment box, this serves as a comment system, if someone wants to leave a comment it is enough to put the name and the comment, when this event occurs the data travels through the get method and then the data is stored in my commenti table up to this point there is no problem with my next code
<form method="get" action="conexion.php">
<input type="text" name="name">
<textarea rows="5" cols="5" name="commento"></textarea>
<input type="submit" value="enviar">
</form>
<?php
$conexion = mysql_connect('localhost', 'root', 'admin');
mysql_select_db('test', $conexion) or die (mysql_error());
$name = $_GET['name'];
$commento = $_GET['commento'];
$fecha= date("Y-m-d H:i:s");
$sql = "INSERT INTO commenti (nome, commento, fecha) VALUES ('$name', '$commento', '$fecha')" ;
mysql_query($sql);
echo $name;
echo $commento;
With this I get the name, the comment and the date printed on the page
However, what I want is to be able to visualize all the comments on my main page, for this purpose I have added a while loop that is recovering the data from my commenti table, however there is an error that I can not understand
<form method="get" action="conexion.php">
<input type="text" name="name">
<textarea rows="5" cols="5" name="commento"></textarea>
<input type="submit" value="enviar">
</form>
<?php
$conexion = mysql_connect('localhost', 'root', 'admin');
mysql_select_db('test', $conexion);
$query = "SELECT * FROM commenti";
while($fila = mysql_fetch_array($query)){
echo $fila['nome'];
echo $fila['commento'];
echo $fila['fecha'];
}
?>
Warning: mysql_fetch_array () expects parameter 1 to be resource, string given in F: \ xamp \ htdocs \ local \ basic \ demo.php on line 12