php学习手记

| |
[不指定 2006/06/14 22:16 | by Else ]
本人学习php的主要方法
<?php require_once('../Connections/db.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "0";
     break;
   case "double":
     $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "now()";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}

/*下面是留言本数据库操作的版块
edit为修改留言
re为回复留言
del为删除留言*/

if ($_GET["edit"] == "book") {
 //echo $_POST['title'];
 //修改留言
$updateSQL = sprintf("UPDATE book SET title=%s, content=%s WHERE id=%s",
                      GetSQLValueString($_POST['title'], "text"),
                      GetSQLValueString($_POST['content'], "text"),
                      GetSQLValueString($_POST['id'], "int"));
 mysql_select_db($database_db, $db);
 $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
 $updateGoTo = "adminbook.php";
 header(sprintf("Location: %s", $updateGoTo));
}


//回复留言
if ($_GET['re']=="book"){
$updateSQL = sprintf("UPDATE book SET recon=%s WHERE id=%s",
                      GetSQLValueString($_POST['recon'], "text"),
                      GetSQLValueString($_POST['id'], "int"));
 mysql_select_db($database_db, $db);
 $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
 $updateGoTo = "adminbook.php";
 header(sprintf("Location: %s", $updateGoTo));
}//回复留言结束了!


//删除留言
if ($_GET['del']=="book"){
$deleteSQL = sprintf("DELETE from book WHERE id=%s",
           GetSQLValueString($_GET['id'],"int"));
 mysql_select_db($database_db,$db);
 $Result = mysql_query($deleteSQL,$db) or die(mysql_error());
 $deleteGoTo="adminbook.php";
 header(sprintf("Location:%s",$deleteGoTo));
}//删除留言结束



/*下面是文章分类的数据库操作
save是添加新记录
edit是修改记录
del是删除记录
传递方法$_GET,$_POST*/

if ($_GET['cat']=="save"){
 $insertSQL = sprintf("INSERT INTO artcat (catname, list, pid, view, catcon, menu, ruby) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString(htmlspecialchars($_POST['catname']), "text"),  //分类名称
                      GetSQLValueString($_POST['list'], "int"),    //顺序
                      GetSQLValueString($_POST['pid'], "int"),      //父级分类
            GetSQLValueString($_POST['view'], "int"),    //可视
            GetSQLValueString($_POST['catcon'], "text"),    //分类说明
            GetSQLValueString($_POST['menu'],"int"),      //前台导航显示
            GetSQLValueString($_POST['ruby'],"int"));    //前台版块
 mysql_select_db($database_db,$db);
 $Result = mysql_query($insertSQL,$db) or die(mysql_error());
 $insertGoTo="adminartcat.php";
 header(sprintf("Location:%s",$insertGoTo));
}//添加记录结束

//修改保存记录开始
if ($_GET['cat']=="edit"){
 $updateSQL = sprintf("UPDATE artcat SET catname=%s, list=%s,  pid=%s, `view`=%s, catcon=%s, menu=%s, ruby=%s WHERE id=%s",//view是关键字
                      GetSQLValueString(htmlspecialchars($_POST['catname']), "text"),
            GetSQLValueString($_POST['list'], "int"),
                      GetSQLValueString($_POST['pid'], "int"),
                      GetSQLValueString(isset($_POST['view']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['catcon'], "text"),
                      GetSQLValueString(isset($_POST['menu']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString(isset($_POST['ruby']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['id'], "int"));

 mysql_select_db($database_db, $db);
 $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
 $updateGoTo="adminartcat.php";
 header(sprintf("Location:%s",$updateGoTo));

}//修改记录结束

//删除分类
if ($_GET['cat']=="del"){
$deleteSQL = sprintf("DELETE from artcat WHERE id=%s",
           GetSQLValueString($_GET['id'],"int"));
 mysql_select_db($database_db,$db);
 $Result = mysql_query($deleteSQL,$db) or die(mysql_error());
 $deleteGoTo="adminartcat.php";
 header(sprintf("Location:%s",$deleteGoTo));
}//删除分类结束


//2006年的06月16日在学校美术系机房开始了文章添加,本来没有打算去吃饭,后来小琴来了,就回去吃饭了!
//现在以是15:33了,听着小湖的MP3开始这了这相近又相远的程序

//下面是文章添加
//ruby=save
if ($_GET['ruby']=="save"){
 $insertSQL = sprintf("INSERT INTO ruby (title, content, author, keyword, `view`, uptop, copyfrom, type, catid, `time`, url, picnews, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString(htmlspecialchars($_POST['title']), "text"),
                      GetSQLValueString($_POST['content'], "text"),
                      GetSQLValueString($_POST['author'], "text"),
                      GetSQLValueString($_POST['keyword'], "text"),
                      GetSQLValueString(isset($_POST['view']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString(isset($_POST['uptop']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['copyfrom'], "text"),
                      GetSQLValueString($_POST['type'], "text"),
                      GetSQLValueString($_POST['catid'], "int"),
                      GetSQLValueString($_POST['time'], "date"),
                      GetSQLValueString($_POST['url'], "text"),
                      GetSQLValueString(isset($_POST['picnews']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['photo'], "text"));

 mysql_select_db($database_db, $db);
 $Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
 $insertGoTo="adminruby.php";
 header(sprintf("Location:%s",$insertGoTo));
}

if ($_GET['ruby']=="edit"){
 $updateSQL = sprintf("UPDATE ruby SET title=%s, content=%s, author=%s, keyword=%s, `view`=%s, uptop=%s, copyfrom=%s, type=%s, catid=%s, url=%s, picnews=%s, photo=%s WHERE id=%s",
                      GetSQLValueString(htmlspecialchars($_POST['title']), "text"),
                      GetSQLValueString($_POST['content'], "text"),
                      GetSQLValueString($_POST['author'], "text"),
                      GetSQLValueString($_POST['keyword'], "text"),
                      GetSQLValueString(isset($_POST['view']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString(isset($_POST['uptop']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['copyfrom'], "text"),
                      GetSQLValueString($_POST['type'], "text"),
                      GetSQLValueString($_POST['catid'], "int"),
                      GetSQLValueString($_POST['url'], "text"),
                      GetSQLValueString(isset($_POST['picnews']) ? "true" : "", "defined","1","0"),
                      GetSQLValueString($_POST['photo'], "text"),
                      GetSQLValueString($_POST['id'], "int"));

 mysql_select_db($database_db, $db);
 $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
 $updateGoTo="adminruby.php";
 header(sprintf("Location:%s",$updateGoTo));
 }//修改结束
 
 
//删除文章
if ($_GET['ruby']=="del"){
$deleteSQL = sprintf("DELETE from ruby WHERE id=%s",
           GetSQLValueString($_GET['id'],"int"));
 mysql_select_db($database_db,$db);
 $Result = mysql_query($deleteSQL,$db) or die(mysql_error());
 $deleteGoTo="adminruby.php";
 header(sprintf("Location:%s",$deleteGoTo));
}//删除文章结束
 
 
?>

<?php //把这个段放在最后面吧!因为一直都要调用数据库了
 mysql_free_result($rs);
 
 //GetSQLValueString这个函数是dw 里面产生的,还真是好用!我自己在里面加了一个now()呵 mysql支持 这样的话,就可以定义我们的时间了
 //htmlspecialchars这个是php里面就有一的一个函数!<将特殊字符转成 HTML 格式>。
?>


作者:Else 's Blog
地址:http://www.aixq.com/post/279/
版权所有。转载时必须链接形式注明作者和原始出处及本声明!
  • 中查看更多“php学习手记”相关内容
  • 中查看更多“php学习手记”相关内容
  • 中查看更多“php学习手记”相关内容
  • 中查看更多“php学习手记”相关内容
  • 中查看更多“php学习手记”相关内容
  • 中查看更多“php学习手记”相关内容

  • 最后编辑: Else 编辑于2006/09/07 10:36
    Tags: ,
    代码 程序 编程 | 评论(0) | 引用(0) | 阅读(2672)
    发表评论
    表情
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    昵称   密码   游客无需密码
    网址   电邮   [注册]