PHP不向xampp数据库发送数据
我正在学习一系列教程(),其中我正在学习创建一个网页的评论部分。我使用的是XAMPP,因为它是视频中的那个家伙正在使用的。我已经完成了将数据(名称、时间、消息)发送到数据库的代码的编写,当我去尝试时,什么都没有发生。我检查了数据库,什么都没有 代码如下: index.phpPHP不向xampp数据库发送数据,php,mysql,forms,function,xampp,Php,Mysql,Forms,Function,Xampp,我正在学习一系列教程(),其中我正在学习创建一个网页的评论部分。我使用的是XAMPP,因为它是视频中的那个家伙正在使用的。我已经完成了将数据(名称、时间、消息)发送到数据库的代码的编写,当我去尝试时,什么都没有发生。我检查了数据库,什么都没有 代码如下: index.php <?php date_default_timezone_set('Europe/London'); include 'dbh.inc.php'; include 'comments.inc.php'; ?>
<?php
date_default_timezone_set('Europe/London');
include 'dbh.inc.php';
include 'comments.inc.php';
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
echo"<form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
</body>
</html>
改变
<?php
echo"<form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
致:
最后
$conn = mysqli_connect('localhost', 'root', '', 'commentsection');
致:
已测试并正在运行“*请帮助我。谢谢”-。$result=mysql\u query($sql)
无法与mysqli_uuAPI一起使用,您知道吗?好吧,如果不是,你现在可以;-)您可以在这里进行sql注入;如果您不希望数据库有一天被破坏/删除,请使用预先准备好的语句。这不起作用“TLDR;找到一个新的教程测试并处理什么?mysql\u query
在当前版本的PHP中已经多年没有出现过了。
<?php
echo"<form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
<?php
// action empty send the post data to the this fila again
// setComments function have a condition to work only when POST data is present
setComments($conn);
echo"<form method='POST' action=''>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
$sql = "INSTERT INTO comments (uid, date, message) VALUES ('$uid', '$date', '$message')";
$result = mysql_query(- $sql);
}
// INSERT is the correct sintaxis
$sql = "INSERT INTO comments (uid, date, message) VALUES ('$uid', '$date', '$message')";
$result = mysql_query($sql);
}
$conn = mysqli_connect('localhost', 'root', '', 'commentsection');
// mysqli_connect have diferent parameters
$conn = mysql_connect('localhost', 'root', '', 'commentsection');