亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Add function (2)

Let’s take a look at the php code to add functions.

Adding data must be added to the database, so the first step must be to connect to the database first.

<?php
$link = mysqli_connect("localhost","root","root","joke");
  if (!$link) {
             die("連接失敗: " . mysqli_connect_error());
        }
?>

We may also need to use the code to connect to the database later, so we can Extract this code and put it in a separate file. In the future, you can directly reference the file, such as naming it config.php. In the future, we only need to include and reference it.

The next step is to receive the value passed by the front-end form page. It is the same as the previous registration.

The other thing about image uploading is to implement it by instantiating the calling class method. Of course you can also write it yourself.

<?php
if($_POST){
  date_default_timezone_set("PRC");         //設(shè)置時區(qū)
  $author = isset($_POST['author'])?$_POST['author']:"";     //獲取表單傳遞過來的值
  $content = isset($_POST['content'])?$_POST['content']:"";
  $cid = isset($_POST['cid'])?$_POST['cid']:"";
 require 'fileupload.class.php';                           //引用類文件
 $upobj=new FileUpload();                                  //實例化調(diào)用類
 $ret=$upobj->upload('pic');
 if($ret==1){
   $creat_time = date("Y-m-d H:i:s");
?>

The function date_default_timezone_set() sets the time zone, and "PRC" represents the Chinese time zone.

When using the reference class method, you need to know something about the class file, otherwise reference errors may occur.

The next step is to insert the received data into the database, use the insert into statement

<?php
if($author && $content && $creat_time && $cid){
   $sql ="insert into list(author,content,creat_time,image,cid) values('$author','$content','$creat_time','{$upobj->newpath}',$cid)";
   $rel = mysqli_query($link,$sql);
   if($rel) {
     echo "添加成功" . "<br/><br/>";
     echo "<a href='list.php'>跳轉(zhuǎn)至列表頁面</a>";
   }
 }else {
   echo "添加失敗" . "<br/><br/>";
   echo "<a href='add.php'>跳轉(zhuǎn)至添加頁面</a>";
 }
}
?>

First write the insert statement, then execute the insert statement, assign the return value to the variable $rel, and determine whether $rel is If there is no value, the addition will be successful. If not, the addition will fail.

Finally, our added function is complete.

Continuing Learning
||
<?php session_start(); header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","joke"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } if($_POST){ date_default_timezone_set("PRC"); $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; $cid = isset($_POST['cid'])?$_POST['cid']:""; require 'fileupload.class.php'; $upobj=new FileUpload(); $ret=$upobj->upload('pic'); if($ret==1){ $creat_time = date("Y-m-d H:i:s"); if($author && $content && $creat_time && $cid){ $sql ="insert into list(author,content,creat_time,image,cid) values('$author','$content','$creat_time','{$upobj->newpath}',$cid)"; $rel = mysqli_query($link,$sql); if($rel) { echo "添加成功" . "<br/><br/>"; echo "<a href='list.php'>跳轉(zhuǎn)至列表頁面</a>"; } }else { echo "添加失敗" . "<br/><br/>"; echo "<a href='add.php'>跳轉(zhuǎn)至添加頁面</a>"; } } ?> <!DOCTYPE html> <html lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="renderer" content="webkit"> <title></title> <link rel="stylesheet" href="css/pintuer.css"> <link rel="stylesheet" href="css/admin.css"> <script src="js/jquery.js"></script> <script src="js/pintuer.js"></script> <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"> </script> <!--建議手動加在語言,避免在ie下有時因為加載語言失敗導致編輯器加載失敗--> <!--這里加載的語言文件會覆蓋你在配置項目里添加的語言類型,比如你在配置項目里配置的是英文,這里加載的中文,那最后就是中文--> <script type="text/javascript" charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script> </head> <body> <div class="panel admin-panel"> <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加內(nèi)容</strong></div> <div class="body-content"> <!--添加內(nèi)容--> <form method="post" class="form-x" action="" enctype="multipart/form-data"> <div class="form-group"> <div class="label"> <label>圖片:</label> </div> <div class="field"> <input type="file" id="url1" name="pic" class="input tips" style="width:25%; float:left;" value="" data-toggle="hover" data-place="right" data-image="" /> <input type="button" class="button bg-blue margin-left" id="image1" value="+ 瀏覽上傳" style="float:left;"> <div class="tipss">圖片尺寸:500*500</div> </div> </div> <div class="form-group"> <div class="label"> <label>分類標題:</label> </div> <div class="field"> <select name="cid" class="input w50"> <option value="">請選擇分類</option> <option value="1">搞笑段子</option> <option value="2">搞笑圖片</option> </select> <div class="tips"></div> </div> </div> <div class="form-group"> <div class="label"> <label>內(nèi)容:</label> </div> <div class="field"> <textarea name="content" class="" id="content" style="height:450px;"></textarea> <div class="tips"></div> </div> </div> <div class="form-group"> <div class="label"> <label>發(fā)布時間:</label> </div> <div class="field"> <script src="js/laydate/laydate.js"></script> <input type="text" class="laydate-icon input w50" name="creat_time" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value="" data-validate="required:日期不能為空" style="padding:10px!important; height:auto!important;border:1px solid #ddd!important;" /> <div class="tips"></div> </div> </div> <div class="form-group"> <div class="label"> <label>作者:</label> </div> <div class="field"> <input type="text" class="input w50" name="author" value="" /> <div class="tips"></div> </div> </div> <div class="clear"></div> <div class="form-group"> <div class="label"> <label></label> </div> <div class="field"> <button class="button bg-main icon-check-square-o" type="submit"> 提交</button> </div> </div> </form> </div> </div> <script type="text/javascript"> //實例化編輯器 //建議使用工廠方法getEditor創(chuàng)建和引用編輯器實例,如果在某個閉包下引用該編輯器,直接調(diào)用UE.getEditor('editor')就能拿到相關(guān)的實例 UE.getEditor('content',{initialFrameWidth:1500,initialFrameHeight:400,}); </script> </body> </html>
submitReset Code