php简单插入表单
我是PHP新手,只需尝试简单表单,但对insert.PHP页面有问题 首先,我的数据库由4条记录(id、姓名、电话号码、日期)组成。id列是自动递增页面 我创建了一个页面调用索引php来显示信息,效果很好 但问题是insert.php页面无法加载该页面,无法插入值并在索引php页面中查看新的插入值php简单插入表单,php,mysql,database,mysqli,Php,Mysql,Database,Mysqli,我是PHP新手,只需尝试简单表单,但对insert.PHP页面有问题 首先,我的数据库由4条记录(id、姓名、电话号码、日期)组成。id列是自动递增页面 我创建了一个页面调用索引php来显示信息,效果很好 但问题是insert.php页面无法加载该页面,无法插入值并在索引php页面中查看新的插入值 <?php if(isset($_post['name'])){ $mysqli = new mysqli('localhost','root',
<?php
if(isset($_post['name'])){
$mysqli = new mysqli('localhost','root','','interdet');
$statement =$mysqli->prepare("INSERT INTO detectives(name)VALUES(?,?)";
$statement->bind_param('ss',$_POST['name']);
$statement->execute();
echo "Done! <a href='index.php'>Go here see new detective </a>";
}
else {
?>
<form action="insert.php" method="POST">
<p>Name : <input type="text" name="name" /> <P>
<p><input type="submit"/></p>
</form>
<?php } ?>
首先,glence,我可以告诉你你试图绑定两个参数,但你只绑定了一个 再看一眼,你的备忘上也少了一个结束括号
$statement =$mysqli->prepare("INSERT INTO detectives(name)VALUES(?,?)");
// ^^^ ?
$statement->bind_param('ss',$_POST['name']);
// ^^ ^^^^^^^^^^^^^^ ???
很抱歉,但看看你的代码,我觉得一切都很好,只是我不明白这句话:
$statement =$mysqli->prepare("INSERT INTO detectives(name)VALUES(?,?)";
Prepare opens the bracket ( but doesn't close it)
这是问题吗 在一列中插入“name”,但绑定两个值。我认为正确的语法是:
$statement =$mysqli->prepare("INSERT INTO detectives(name)VALUES(?)");
$statement->bind_param('s',$_POST['name']);
$statement->execute();
那么
电话号码
和日期
呢?您没有插入它们,它们是否有默认值?或者他们是否允许NULL
表单和insert sql是否在同一页中?问题在哪里?你试图用什么方法来解决这个问题?“你想找出什么,问题是什么?”查玛拉多山卡:如果这个答案解决了你的问题,考虑一下投票和接受它,点击大的绿色刻度标记。✔) 在答案的分数下。但数据不插入到db@ChamaraMadhushanka:那么…你为什么认为这个答案是正确的?请阅读我的答案,我打赌这是你的问题。@MadaraUchiha因为现在有太多的noobs,所以包括OPi accept,我很高兴没有页面错误(页面加载),但数据没有插入数据库