码迷,mamicode.com
首页 > 其他好文 > 详细

友情链接的添加保存

时间:2015-05-29 23:05:58      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

linkaddsave.php (保存php页面)

 1 <?php
 2 include ‘../inc/db_mysqli.php‘;
 3 $ty = $_POST[‘ty‘];
 4 if($ty==‘Y‘){
 5     //纯文字友情链接,不用保存图片
 6     $stmt = $m->prepare(‘insert into hnsc_link(ltype,title,url,flag,atime) values(?,?,?,?,?)‘);
 7     $stmt->bind_param(‘ssssi‘,$ty,$title,$url,$flag,$atime);
 8     $title = $_POST[‘title‘];
 9     $url = $_POST[‘url‘];
10     $flag = $_POST[‘flag‘];
11     $atime = time();
12     $stmt->execute();
13     $stmt->free_result();
14     $stmt->close();
15     $m->close();
16     header(‘location:linkmanager.php‘);
17 }else{
18        //保存上传图片
19 }
db_mysqli.php
<?php
$host = ‘localhost‘;
$user = ‘root‘;
$pass = ‘‘;
$dbname = ‘hnscdb‘;
$charset = ‘utf8‘;
$m = new mysqli($host,$user,$pass,$dbname);
$m->set_charset($charset);

function mymd5($p,$c=‘webrx‘){
    $s1 = md5($p.$c);
    $s2 = sha1($p.$c);
    $sok = substr($s1,0,6).substr($s2,0,6);
    $sok .= substr($s1,12,5).substr($s2,22,5);
    $sok .= substr($s1,22,5).substr($s2,32,5);
    return $sok;
}

function pager($tn,$currpage=1,$f=‘*‘,$pagesize=3,$w=‘1=1‘){
    global $m;
    $stmt = $m->prepare("select count(*) from $tn where $w");
    $stmt->execute();
    $stmt->bind_result($recordcount);
    $stmt->fetch();
    $stmt->free_result();
    $stmt->close();
    
    $stmt = $m->prepare("select $f from $tn where $w limit ?,?");
    $pagecount = ceil($recordcount/$pagesize);
    $start = $currpage*$pagesize - $pagesize;
    $stmt->bind_param(‘ii‘,$start,$pagesize);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = array();
    $row[] = $result->fetch_all( MYSQLI_NUM);
    $stmt->free_result();
    $stmt->close();

    $first = 1;
    $end = 10;
    $pages = ‘<div class="page">‘;
    if($currpage>=7){
        $first = $currpage-5;
        $end = $first+$end-1;
    }
    if($currpage>1){
        $prev = $currpage-1;
        if($first>1){
            $pages.="<a href=?p=1>首页</a><a href=?p=$prev>上一页</a>";
        }else{
            $pages.="<a href=?p=$prev>上一页</a>";            
        }
    }
    for($i=$first;$i<=$end;$i++){
        if($i>$pagecount){
            break;    
        }
        if($i==$currpage){
            $pages.=‘<a class="checked">‘.$i.‘</a>‘;
            continue;    
        }
        $pages.="<a href=?p=$i>$i</a>";
    }
    if($currpage<$pagecount){
        $next = $currpage+1;
        $pages.="<a href=?p=$next>下一页</a>";        
    }
    if($end<$pagecount){
        $pages.="<a href=?p=$pagecount>尾页</a>";
    }
    $row[] = $pages.‘</div>‘;
    $row[] = $pagesize;
    $row[] = $pagecount;
    $row[] = $recordcount;
    $row[] = $currpage;
    return $row;
}

function css1(){
    $css = <<<css
    <style>
    .page{font-size:12px;height:30px;padding:15px 0;clear:both;overflow:hidden;text-align:center;}
    .page a{text-decoration:none;line-height:25px;padding:0px 10px;display:inline-block;margin-right:5px;border:solid 1px #c8c7c7;}
    .page a:hover,.page a.checked{text-decoration:none;border:solid 1px #0086d6;background:#0091e3;color:#fff;}
    .page a:visited,.page a:link{color:#333;}
    .page a:active{color:#3B3B3B;}
    </style>
css;
    echo $css;        
}

linkadd.html(后台页面显示)

 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>webrx-title</title>
 6 <style>
 7 div#fff{display:none;}
 8 </style>
 9 </head>
10 
11 <body>
12 <h1>添加网站友情链接</h1>
13 <form action="linkaddsave.php" method="post" enctype="multipart/form-data">
14 类型:
15 <label><input type="radio" name="ty" onclick="s(this)" value="Y" checked>文字类型</label>
16 <label><input type="radio" name="ty" onclick="s(this)" value="N">图片类型</label><br>
17 标题:<input type="text" maxlength="50" name="title" size="20"><br>
18 URL:<input type="text" maxlength="200" name="url" size="50"><br>
19 <div id="fff">图片:<input type="file" name="img"><br></div>
20 是否在网站显示:
21 <label><input type="radio" name="flag" value="Y" checked>显示</label>
22 <label><input type="radio" name="flag" value="N">不显示</label><br>
23 <input type="submit" value="添加友情链接">
24 </form>
25 </body>
26 </html>
27 <script>
28 function s(i){
29     var obj = document.getElementById(‘fff‘);
30     if(i.value==‘Y‘){
31         obj.style.display = ‘none‘;
32     }else{
33         obj.style.display = ‘block‘;
34     }    
35 }
36 </script>

link.php

 1 <div class="links">
 2         <h1 class="linkstit">友情链接<span class="eng">Links</span></h1>
 3         <div class="linkscon">
 4             <ul>
 5                 <?php
 6                 if($stmt=$m->prepare(‘select * from hnsc_link where flag=?‘)){
 7                     $stmt->bind_param(‘s‘,$flag);
 8                     $flag = ‘Y‘;
 9                     $stmt->execute();
10                     $result = $stmt->get_result();
11                     $rows = $result->fetch_all(2);
12                     foreach($rows as $v){
13                         echo ‘<li><a href="‘. $v[3] .‘">‘.$v[2].‘</a></li>‘;
14                     }
15                 }else{
16                     echo ‘<li>无友情链接</li>‘;                        
17                 }
18                 
19                 ?>
20 
21             </ul>
22         </div>
23 </div>

index.php

 1 <?php
 2 include ‘inc/db_mysqli.php‘;
 3 ?>
 4 <!DOCTYPE html>
 5 <html>
 6 <head>
 7 <meta charset="utf-8">
 8 <title>河南仕畅市政工程有限公司、市政工程、河南工程</title>
 9 <meta name="keywords" content="河南工程、市政工程、河南仕畅市政工程有限公司网站、河南市政工程、hnshichang.com">
10 <meta name="description" content="河南工程、市政工程、河南仕畅市政工程有限公司网站、河南市政工程、hnshichang.com">
11 <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
12 <link href="css/style.css" rel="stylesheet">
13 <script src="js/j.js"></script>
14 </head>
15 
16 <body>
17 <?php include ‘nav.html‘;?>
18 
19 <div class="container">
20     <div class="culture fl mr">
21         <h1 class="cultit">企业文化<span class="eng">Culture</span></h1>
22         <div class="culcon0">
23             <p class="cullist"><span class="clbold">计划</span>是时间的最好保障,</p>
24             <p class="cullist"><span class="clbold">时间</span>是效率的坚实基础,</p>
25             <p class="cullist"><span class="clbold">效率</span>是行动的优化大师,</p>
26             <p class="cullist"><span class="clbold">行动</span>是成功的唯一途径 。</p>
27             <p class="cullist"><span class="clbold">经营理念</span>以市场为导向,以出精创优为基础,以服务业主为中心,以良好信誉为根本</p>
28         </div>
29     </div>
30 
31 
32     <div class="intro fl">
33         <h1 class="introtit"><span class="titmore fr"><a href="#">更多&gt;&gt;</a></span>公司简介<span class="eng">Introduction</span></h1>
34         <div class="introcon">
35             <img src="images/abpic.jpg" class="intropic"/>河南仕畅市政工程有限公司成立于2014年6月,注册资金1000万元,拥有市政公用工程三级资格认证,主营业务为:城市道路、公共广场、2万吨/36 给水厂、污水处理工程、供水管道、污水管道、垃圾转运站等。公司有高级专业人员十余人,中级专业技术人员二十余人,三类人员及特种工三十余人。
37         我公司愿真诚与社会各界密切合作,增进友谊,共谋发展。
38         </div>
39     </div>
40 
41 
42 
43     <div class="culture fl ml">
44         <h1 class="cultit">服务中心<span class="eng">Service</span></h1>
45         <div class="sercon">
46             <p class="serlist"><span class="clbold">地址:</span>泌阳县产业集聚区(工业西路)</p>
47             <p class="serlist"><span class="clbold">电话:</span>0396-7636111</p>
48             <p class="serlist"><span class="clbold">网址:</span>www.hnshichang.com</p>
49             <p class="serlist"><span class="clbold">邮箱:</span>shichangshizheng@126.com</p>
50             <p class="chmes"><a href="#"></a></p>
51         </div>
52     </div>
53 
54     <h1 class="clear"></h1>
55 
56     <div class="culture fl mr">
57         <h1 class="cultit">资质荣誉<span class="eng">Aptitude</span></h1>
58         <div class="apcon">
59             <img src="images/zizhi.jpg" />
60         </div>
61     </div>
62 
63 
64 
65     <div class="engineer fr">
66         <h1 class="engtit"><span class="titmore fr"><a href="#">更多&gt;&gt;</a></span>工程展示<span class="eng">Engineering</span></h1>
67         <div class="engcon">
68             <ul>
69                 <li><a href="#"><img src="images/gch.jpg" /></a></li>
70                 <li><a href="#"><img src="images/gch.jpg" /></a></li>
71                 <li><a href="#"><img src="images/gch.jpg" /></a></li>
72                 <li><a href="#"><img src="images/gch.jpg" /></a></li>
73             </ul>
74         </div>
75     </div>
76     <h1 class="clear"></h1>
77     <?php include ‘link.php‘;?>  
78 </div>
79 <?php include ‘footer.html‘;?>
80 </body>
81 </html>

 

友情链接的添加保存

标签:

原文地址:http://www.cnblogs.com/lsr111/p/4539530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!