gpt4 book ai didi

php - 插入数据库不起作用

转载 作者:行者123 更新时间:2023-11-30 01:28:01 25 4
gpt4 key购买 nike

<?php
include("dbinit.php");
$text="helow";
$eadd = $_SESSION['account'];
$result = mysqli_query($link,"SELECT * FROM account where Eadd='". $eadd ."'");
while($row = mysqli_fetch_array($result))
{
$name = $row['Name'];
}
$ctext = $_POST['ctext'];
$sql = "INSERT INTO chat (By, Content, Reported) VALUES ('$name','$ctext','No')";
mysqli_query($link,$sql);
mysqli_close($link);
$text=$name . $ctext;
echo $text;
?>

这是我的代码。在我的其他页面中,这有效,但是..当我更改“插入”中的值时,为什么我无法将其存储到数据库?

<?php
session_start();
$link = mysqli_connect("localhost", "xxx", "xxx", "xxx");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_select_db($link, "xxx");
header('Content-type: text/html; charset=utf-8');
?>

这是我的 dbinit 文件

最佳答案

$sql = "INSERT INTO `chat` (`By`, `Content`, `Reported`) VALUES ('".$name."','".$ctext."','No')";

to protect from mysql injections read this.

另外,您更改为哪种值不起作用?

关于php - 插入数据库不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17771030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com