我的PHP笔记
1、用过的函数
1、empty()
empty()
--------
if (empty($title)) {
...........
}
该函数用于检查一个变量是否为空。
PHP的一些方法
1、连接数据库先
$conn = new mysqli($servername, $username, $password);
我的ThinkPHP笔记
1、前端提交数据给数据库
<form id="changepwd-form" class="form-horizontal" method="POST" action="">
<input type="text" name="isname" placeholder="123456">
<input type="submit">
</form>
if ($this->request->isPost()) {
$isname = $this->request->post("isname");
$user = model('Qiantai');
$user->data([
'name' => $isname
]);
$user->save();
}
2、使用接口来提交数据库
<form action="http://xxxxxx/api/index/tijiao">
<input type="text" name="title">
<input type="text" name="content">
<input type="submit" vuale="123456">
</form>
public function tijiao($title,$content)
{
$a = new Question();
$data = ([
'title' => $title,
'content' => $content
]);
$a->save($data);
}
3、如何判断上传的数据是否重复
我的方法 1、查询数据库判断是否为空
public function index()
{
$a = new Feed();
if ($this->request->isPost()) {
$title = $this->request->post("title");
$content = $this->request->post("content");
$titlea = Feed::where('title','=',$title)->select();
if ($titlea == NULL) {
$data = ([
'title' => $title,
'content' => $content
]);
$a->save($data);
} else {
echo '该数组有重复值';
}
}
return $this->view->fetch();
}
|