I would be really grateful if someone can help me solve my problem. the problems is that when I click POST enter image description hereshowing me this error:
> *PHP Warning: mysqli_connect(): (HY000/2002):� in C:\Users\21145\Desktop\www\list.php on line 3
PHP Fatal error: Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, bool given in C:\Users\21145\Desktop\www\list.php:4
Stack trace:
#0 C:\Users\21145\Desktop\www\list.php(4): mysqli_query(false, 'set names gbk')
#1 {main}
thrown in C:\Users\21145\Desktop\www\list.php on line 4*
this is my code
list.php
<?php
$link = mysqli_connect('localhost','root','123456');
mysqli_query($link,"set names gbk");
if(!$link){
die("Could not connect to MySQL: ".mysqli_error());
}
echo 'Connection OK ';
echo "<br>";
$name = $_POST["name"];
$comment = $_POST["comment"];
mysqli_select_db($link,'test');
$query = "insert into comment (uname,ucomment) value ('{$name}','{$comment}'); ";
if(!mysqli_query($link,$query))
{
die("Error: ".mysqli_error($link));
}
$result = mysqli_query($link,"SELECT uname,ucomment FROM comment;");
while($row = mysqli_fetch_array($result))
{
echo $row["uname"] . "<br/>";
echo $row["ucomment"] . "<br/>";
}
mysqli_close($link); #关闭数据库
echo "<meta http-equiv='refresh' content='0;url=home.php'>"; //return home.php
?>