<?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文件
答案 0 :(得分:1)
$sql = "INSERT INTO `chat` (`By`, `Content`, `Reported`) VALUES ('".$name."','".$ctext."','No')";
to protect from mysql injections read this.
另外,你改变了什么样的价值不起作用?
答案 1 :(得分:0)
BY
是保留关键字,你应该使用反引号
$sql = "INSERT INTO chat (`By`, Content, Repo.........
答案 2 :(得分:-1)
用双引号将PHP变量包装在$ sql中,不要忘记点。
$sql = "INSERT INTO chat (By, Content, Reported) VALUES ('".$name."','".$ctext."','No')";