php开发留言板之页面提交php文件

留言板页面提交php文件

QQ截图20161130141717.png

<?php

include ("conn.php");
$id=$_POST['id'];
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];
if ($_POST['submit']){
  $sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";
    mysql_query($sql);
    echo "<script>alert('提交成功!返回首页。');location.href='add.html';</script>";
}
?>

调用数据库连接文件,当点击submit时用post提交方式,使用sql语insert into 对message表内的id user title content lasdata 写入文件

echo "<script>alert('提交成功!返回首页。');location.href='add.html';</script>";

是使用js来进行弹窗提示并返回。


难点:

$_POST的使用和获取方法

继续学习
||
<?php include ("conn.php"); $id=$_POST['id']; $user=$_POST['user']; $title=$_POST['title']; $content=$_POST['content']; if ($_POST['submit']){ $sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())"; mysql_query($sql); echo "<script>alert('提交成功!返回首页。');location.href='add.html';</script>"; } ?>
提交重置代码
  • 推荐课程
  • 评论
  • 问答
  • 笔记
  • 课件下载
笵

有些代码是错误的,$id可以删掉,now()不要,mysql_query($sql)改为mysqli_query($conn,$sql) 需要两个参数

2年前    添加回复 0

回复
廣zeen

廣zeen

mysqli_query(表名,mysql命令);

2年前    添加回复 0

回复
二少爷

二少爷

我草你妈 php 有now()函数吗

3年前    添加回复 0

Here I am

mysqli可以用now()的哟,我试过,没问题

Here I am · 2018-07-28 11:46
回复
y的小公举

y的小公举

自学的困难只有自己知道,如何让学习不再困难让学习提高效率

3年前    添加回复 0

回复
记住我

记住我

mysql_query()不能用了,用mysqli_query();

3年前    添加回复 0

回复
phpcn_u91209

phpcn_u91209

按照上面的代码处理报错啊?啥问题? Notice: Undefined index: id in C:\phpStudy\PHPTutorial\WWW\BBS\add.php on line 4 aaa Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\phpSt

3年前    添加回复 0

廣zeen

$id=$_POST['id'];毫无必要,还会报错。删掉就可以了

廣zeen · 2019-04-14 00:37
回复
phpcn_u91209

phpcn_u91209

按照上面的代码处理报错啊?啥问题? Notice: Undefined index: id in C:\phpStudy\PHPTutorial\WWW\BBS\add.php on line 4 aaa Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\phpSt

3年前    添加回复 0

回复

这个入门教程代码感觉是瞎打的没测试吧

[最新 秋香姐家的小书童 的回答]这不是坑 也不是错误 , 图文教程  include ("conn.php");  在文件里就没有conn.php这个文件 你要学习的时候 一步一步按教程来 不要使用在线执行代码的工具

时间:2年前

$id=$_POST['id'];

[最新 Here I am 的回答]我感觉add.html里面没有id为id的,所以我感觉那行代码可以不要

时间:4年前

post中没有id值

1年前 0

课件暂不提供下载,工作人员正在整理中,后期请多关注该课程~