我是第一次使用 HTML PHP 和 Ajax,所以请耐心等待。大部分代码来自我在网上找到的示例。但是,我无法让它实际插入数据库。 ajax函数确实进入成功函数;成功输出只是显示为警报的 php 文件。
我把这些都放在本地了,所以我启动 chrome 作为
chrome --allow-file-access-from-files file:///C:/filepath/index2.html
我知道这不好,但我正在凑合着。
index.html
Insert
插入.php
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql="INSERT INTO data ('id', 'name', 'email') VALUES (NULL, $name, $email)";
if ($conn->query($sql) === TRUE) {
echo "data inserted";
}
else
{
echo "failed";
}
?> Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号