主页 > 编程 > php >

同城信息网免费发布信息 insert into语句数据添加

2019-01-12 13:19 阅读:173 来源:智宇SEO自媒体

  运行环境:win10 64位  php5.45 Apache   mysqlnd 5.0.10

  文件:release.php(信息发布页面)  release_add.php(信息插入数据库操作)  conn.php(数据库服务器链接)

  功能:完成免费发布信息操作

  实现:熟悉 insert into语句

同城信息网免费发布信息 熟悉mysql数据插入 insert into语句
 

  insert into语句 插入新数据操作

<?php
header ( "Content-type: text/html; charset=utf-8" );
class FreeInfoAdd
{
    //信息类型
    public $type;
    //标题
    public $title;
    //内容
    public $content;
    //联系人
    public $man;
    //联系电话
    public $tel;
    //发布时间
    public $datetime;
    //审核
    public $tag;

    public function __construct($type,$title,$content,$man,$tel,$datetime,$tag=0)
    {
     $this->type=$type;
     $this->title=$title;
     $this->content=$content;
     $this->man=$man;
     $this->tel=$tel;
     $this->datetime=$datetime;
     $this->tag=$tag;
    }
     public function infoAdd()
    {

    include("conn.php");
    $sql="insert into free(type,title,content,man,tel,date,tag) values('{$this->type}','{$this->title}','{$this->content}','{$this->man}','{$this->tel}','{$this->datetime}','{$this->tag}')";

     if(mysqli_query($conn,$sql))
    {
        echo "<script>alert('恭喜您,信息发布成功!');window.location.href='release.php';</script>";
    }
    else
    {
         echo "<script>alert('对不起,信息发布失败!');history.back();</script>";
    }

    }

}   //时区设置
    date_default_timezone_set("PRC");
    $type=$_POST['type'];
    $title=$_POST['title'];
    $content=$_POST['content'];
    $man=$_POST['man'];
    $tel=$_POST['tel'];
    $edate=date("Y-m-d H:i:s");

    $obj=new  FreeInfoAdd($type,$title,$content,$man,$tel,$edate);
    $obj->infoAdd();

  数据库链接

<?php

//连接mysql服务器
$conn=mysqli_connect("localhost","root","root") or die("数据库服务器连接错误".mysqli_error());
mysqli_select_db($conn,"tc") or die("数据库访问错误".mysqli_error());
mysqli_query($conn,"set names utf8");//采用utf8编码格式

  SQL代码

DROP TABLE IF EXISTS `free`;
CREATE TABLE `free` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `type` varchar(25) NOT NULL,
  `title` varchar(50) NOT NULL,
  `content` text NOT NULL,
  `man` varchar(20) NOT NULL,
  `tel` varchar(20) NOT NULL,
  `date` datetime NOT NULL,
  `tag` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

完整代码下载 链接: https://pan.baidu.com/s/1GXrfySGAtQEBziSfi5bbJw 提取码: t58i