【金沙澳门官网7817网址】php留言板程序(适合php初学者)

html xmlns=”,”,html xmlns=”,”

<?php教程
require_once(dirname(__file__).”/../include/common.inc.php”);
if(emptyempty($dopost))
{
$dopost = “”;
}
if($dopost==”rename”)
{
if(rename(‘dedesql.query.php’,’arc.sqlquery.class.php’)){
echo “成功!”;
}else{
echo “失败!”;
}
exit();
}
if($dopost==”viewinfo”)
{
if(emptyempty($tablename))
{
echo “未有一点点名表名!”;
}
else
{
$dsql->setquery(“show create table
“.$dsql->dbname.”.”.$tablename);
$dsql->execute(‘me’);
$row2 =
$dsql->getarray(‘me’,mysql教程_both);
$ctinfo = $row2[1];
echo “<xmp>”.trim($ctinfo).”</xmp>”;
}
exit();
}
if($dopost==”index”)
{
require_once(dedeinc.’/arc.partview.class.php’);
$envs = $_sys_globals = array();
$envs[‘aid’] = 0;
$pv = new partview();
$row = $pv->dsql->getone(‘select * from
`#@__homepageset`’);
$templet =
str_replace(“{style}”,$cfg_df_style,$row[‘templet’]);
$homefile = dirname(__file__).’/’.$row[‘position’];
$homefile =
str_replace(“//”,”/”,str_replace(“”,”/”,$homefile));
$fp = fopen($homefile,’w’) or
die(“不能够创新网站主页到:$homefile 位置”);
fclose($fp);
$tpl = $cfg_basedir.$cfg_templets_dir.’/’.$templet;
$pv->settemplet($tpl);
$pv->savetohtml($homefile);
$pv->close();
echo “成功更新首页!”;
exit();
}
else if($dopost==”query”)
{
$sqlquery =
trim(strips教程lashes($sqlquery));
if(eregi(“drop(.*)table”,$sqlquery)
||eregi(“drop(.*)database”,$sqlquery))
{
echo “<span
style=’font-size:10pt’>删除’数据表’或’数据库教程’的语句不容许在此处进行。</span>”;
exit();
}
if(eregi(“^select “,$sqlquery))
{
$dsql->setquery($sqlquery);
$dsql->execute();
if($dsql->gettotalrow()<=0)
{
echo “运转sql:{$sqlquery},无重回记录!”;
}
else
{
echo
“运维sql:{$sqlquery},共有”.$dsql->gettotalrow().”条记下,最大重回100条!”;
}
$j = 0;
while($row = $dsql->getarray())
{
$j++;
if($j>100)
{
break;
}
echo “<hr size=1 width=’100%’/>”;
echo “记录:$j”;
echo “<hr size=1 width=’100%’/>”;
foreach($row as $k=>$v)
{
echo “<font color=’red’>{$k}:</font>{$v}<br/>rn”;
}
}
exit();
}
if($querytype==2)
{
$sqlquery = str_replace(“r”,””,$sqlquery);
$sqls = split(“;[ t]{0,}n”,$sqlquery);
$nerrcode = “”;$i=0;
foreach($sqls as $q)
{
$q = trim($q);
if($q==””)
{
continue;
}
$dsql->executenonequery($q);
$errcode = trim($dsql->geterror());
if($errcode==””)
{
$i++;
}
else
{
$nerrcode .= “推行: <font color=’blue’>$q</font>
出错,错误提醒:<font
color=’red’>”.$errcode.”</font><br>”;
}
}
echo “成功奉行{$i}个sql语句!<br><br>”;
echo $nerrcode;
}
else
{
$dsql->executenonequery($sqlquery);
$nerrcode = trim($dsql->geterror());
echo “成功奉行1个sql语句!<br><br>”;
echo $nerrcode;
}
exit();
}
if($dopost==”view”)
{
;echo ‘<html>
<head>
<meta http-equiv=’content-type’ content=’text/html;
charset=gb2312′>
<title>sql命令行工具</title>
<link
href=’img/base.css教程’
rel=’stylesheet’ type=’text/css’>
</head>
<body background=’img/allbg.gif’ leftmargin=’8′ topmargin=’8′>
<table width=”98%” border=”0″ align=”center” cellpadding=”3″
cellspacing=”1″ bgcolor=”#d1ddaa”>
<tr>
<td height=”19″ background=”img/tbg.gif”>
<table width=”96%” border=”0″ cellspacing=”1″ cellpadding=”1″>
<tr>
<td
width=”24%”><strong>sql命令运营器:</strong></td>
<td width=”76%” align=”right”> <b><a
href=”sys_data.php”><u>数据备份</u></a></b>
| <b><a
href=”sys_data_revert.php”><strong><u>数据恢复</u></strong></a></b>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=”200″ bgcolor=”#ffffff” valign=”top”>
<table width=”100%” border=”0″ cellspacing=”4″
cellpadding=”2″>
<form action=”” method=”post” name=”infoform” target=”stafrm”>
<input type=’hidden’ name=’dopost’ value=’viewinfo’ />
<tr bgcolor=”#f3fbec”>
<td width=”15%” height=”24″
align=”center”>系统的表音信:</td>
<td>
<table width=”100%” border=”0″ cellspacing=”0″
cellpadding=”0″>
<tr>
<td width=”35%”>
<select name=”tablename” id=”tablename” style=”width:100%”
size=”6″>
‘;
$dsql->setquery(“show tables”);
$dsql->execute(‘t’);
while($row = $dsql->getarray(‘t’,mysql_both))
{
$dsql->setquery(“select count(*) from “.$row[0]);
$dsql->execute(‘n’);
$row2 = $dsql->getarray(‘n’,mysql_both);
$dd = $row2[0];
echo ” <option
value='”.$row[0].”‘>”.$row[0].”(“.$dd.”)</option>rn”;
}
;echo ‘ </select>
</td>
<td width=”2%”> </td>
<td width=”63%” valign=”bottom”>
<div style=”float:left;margin-right:20px;”>
<input type=”submit” name=”submit1″ value=”优化选中表”
class=”coolbg np” onclick=”this.form.dopost.value=’opimize’;” />
<br />
<input type=”submit” name=”submit2″ value=”修复选中表”
class=”coolbg np” onclick=”this.form.dopost.value=’repair’;”
style=”margin-top:6px;” />
<br />
<input type=”submit” name=”submit3″ value=”查看表结构”
class=”coolbg np” onclick=”this.form.dopost.value=’viewinfo’;”
style=”margin-top:6px;” />
</div>
<div style=”float:left”>
<input type=”submit” name=”submit5″ value=”优化整个表”
class=”coolbg np” onclick=”this.form.dopost.value=’opimizeall’;”
/>
<br />
<input type=”submit” name=”submit6″ value=”修复整个表”
class=”coolbg np” onclick=”this.form.dopost.value=’repairall’;”
style=”margin-top:6px;” />
</div>
</td>
</tr>
</table></td>
</tr>
<tr>
<td height=”200″ align=”center”>重临新闻:</td>
<td>
<iframe name=”stafrm” frameborder=”0″ id=”stafrm” width=”100%”
height=”100%”></iframe>
</td>
</tr>
</form>
<form action=”” method=”post” name=”form1″ target=”stafrm”>
<input type=’hidden’ name=’dopost’ value=’query’>
<tr>
<td height=”24″ colspan=”2″
bgcolor=”#f3fbec”><strong>运行sql命令行:
<input name=”querytype” type=”radio” class=”np” value=”0″>
单行命令(帮衬轻巧询问)
<input name=”querytype” type=”radio” class=”np” value=”2″
checked>
多行命令</strong></td>
</tr>
<tr>
<td height=”118″ colspan=”2″>
<textarea name=”sqlquery” cols=”60″ rows=”10″ id=”sqlquery”
style=”width:90%”></textarea>
</td>
</tr>
<tr>
<td height=”53″ align=”center”> </td>
<td>
<input name=”imagefield” type=”image” src=”img/button_ok.gif”
width=”60″ height=”22″ border=”0″ class=’np’ />
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
‘;}
?>

 

commond1.php

<br />
注:”+”为存在子目录,能够开始展览,”-“为终极分类.
</body>
</html>

<?php
 require (“common.php”);
 mysql_query(‘delete from gb_content where
id=’.intval($_get[“id”]));
 echo ‘已删除!<a href=”index.php”>查看留言</a>’;
?>

 

 代码如下

 ?>
<table width=”551″ border=”0″ cellpadding=”0″ cellspacing=”1″
bgcolor=”#cccccc”>
<form action=”” method=”post” name=”form1″>
  <tr>
    <td height=”28″ colspan=”2″ align=”center”
bgcolor=”#ffffff”>编辑栏目</td>
  </tr>
  <tr>
    <td width=”246″ height=”28″ align=”right”
bgcolor=”#ffffff”>栏目名称:</td>
    <td width=”302″ height=”28″ bgcolor=”#ffffff”><input
name=”name” type=”text” id=”name” value=”<?php echo
$rsa[‘name’];?>” /></td>
  </tr>
  <tr>
    <td height=”28″ align=”right”
bgcolor=”#ffffff”>所属分类:</td>
    <td height=”28″ bgcolor=”#ffffff”><select name=”bid”>
 <?php
   $sql=”select * from tvmenu where bid<>’$rsa[‘bid’]'”;
     $que=mysql_query($sql,$conn);
           while($rs=mysql_fetch_array($que)){
     if ($rs[“id”]==$rsa[‘bid’]) {
     $selected=”selected=”selected””;
     }else{
     $selected=””;
     }
 ?>
 
      <option value=”<?php echo $rs[“id”]; ?>” <?php echo
$selected;?>><?php echo $rs[“name”]; ?></option>
  <?php }?>
    </select>
    </select>
    </td>
  </tr>
  <tr>
    <td height=”28″ colspan=”2″ align=”center”
bgcolor=”#ffffff”><input type=”submit” name=”submit” value=”提
交” /></td>
  </tr>
  </form>
</table>
<?php }?>

  function nun_row($query ){
   return mysql_num_row($query);
  }

— 导出表中的数据 `tvmenu`

insert into `tvmenu` (`id`, `bid`, `name`, `url`) values
(1, 0, ‘电视1’, ”),
(2, 0, ‘电视2’, ”),
(3, 1, ‘电视3’, ”),
(4, 1, ‘电视4’, ”),
(5, 2, ‘电视5’, ”),
(6, 2, ‘电视6’, ”),
(7, 3, ‘电视7’, ”),
(8, 3, ‘电视8’, ”),
(9, 3, ‘电视9’, ”),
(10, 5, ‘电视10’, ”),
(11, 5, ‘电视11’, ”),
(12, 5, ‘电视12’, ”),
(13, 6, ‘电视13’, ”),
(14, 6, ‘电视1422’, ”);

*/?>

 

 $sql=”select * from tvmenu where id=’$b'”;
 //echo $sql ;
 //exit;
 $quea=mysql_query($sql,$conn);
 $rsa=mysql_fetch_array($quea);

while ($row = mysql_fetch_array($result, mysql_both)) {//
取一条数据
?>
<table width=”700″ border=”0″ cellspacing=”0″ cellpadding=”0″
class=”tb”>
  <tr>
    <td class=”bg”><b>[<?php echo
htmlentities($row[‘username’],ent_compat,’utf-8′) ?>]</b>
发表于:<?php echo
htmlentities($row[‘insert_time’],ent_compat,’utf-8′)
?></td>
  </tr>
  <tr>
    <td><?php echo
htmlentities($row[‘content’],ent_compat,’utf-8′) ?></td>
  </tr>
  <tr>
    <td align=”right”><a href=”edit.php?id=<?php echo
$row[‘id’] ?>”>修改</a> <a href=”delete.php?id=<?php
echo $row[‘id’] ?>”>删除</a></td>
  </tr>
</table>
<?php
}

<?php if ($tpye==”edit”) {

 // insert sql语句
 $sql = “insert into gb_content (username,content,insert_time)
   values
(‘”.$_post[‘username’].”‘,'”.$_post[‘content’].”‘,'”.date(‘y-m-d
h:i:s’).”‘)”;
 mysql_query($sql,$link);// 执行sql查询
 echo ‘增加成功! <a href=”index.php”>查看留言</a>’;
 exit;
}
?>
<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en”
“;
<html xmlns=”;
<head>
<meta http-equiv=”content-type” content=”text/html; charset=gbk”
/>
<title>提交留言</title>
<link rel=”stylesheet” type=”text/css” href=”style.css” media=”all”
/>
</head>

 

<body>
<table width=”500″ border=”0″ cellspacing=”0″ cellpadding=”0″
class=”tb”>
  <tr>
    <td class=”bg”><b>[交由留言]</b></td>
  </tr>
  <tr>
    <td><form id=”form1″ name=”form1″ method=”post” 
action=”add.php?action=save”>
        <table width=”500″ border=”0″ cellspacing=”0″
cellpadding=”0″>
          <tr>
            <td width=”15%”>用户名:</td>
            <td width=”88%”><input type=”text” name=”username”
/></td>
          </tr>
          <tr>
            <td width=”12%”>内容:</td>
            <td width=”88%”><textarea name=”content” cols=”40″
rows=”6″></textarea>
            </td>
          <tr>
            <td width=”12%”></td>
            <td width=”88%”><input type=”submit” name=”submit”
value=”提 交”  /></td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
</body>
</html>

— 主机: localhost
— 生成日期: 二〇一〇 年 10 月 21 日 17:19
— 服务器版本: 5.0.45
— php 版本: 5.2.5

set sql_mode=”no_auto_value_on_zero”;

 

— 数据库: `gztv`


mysql_free_result($result);

<?php
//php
 $conn=mysql_connect(“localhost”,”root”,”root”);
 mysql_select_db(“gztv”);  //展开数据库
 mysql_query(“set names ‘gb2312′”); //幸免乱码
 $tpye=trim($_get[“tpye”]);
 $action=$_get[“action”];
 $id=$_get[“id”];
 $b=trim($_get[“b”]);
 $name=$_post[“name”];
 $bid=$_post[“bid”];
 switch ($action) {
 case add:
  $sql=”insert into `gztv`.`tvmenu` (`id` ,`bid` ,`name`
,`url` )values (null , ‘$bid’, ‘$name’, null);”;
     $qu=mysql_query($sql,$conn);
  if($qu){
  $add=””;
  print “<script
language=’javascript’>alert(‘增多成功!’);window.location=’tree.php'</script>”;
  exit;
  }
  break;
 case edit:
  $sql=”update tvmenu set name=’$name’, bid=’$bid’ where id=’$id'”;
      $qu=mysql_query($sql,$conn);
  if($qu){
  $edit=””;
  //header (“location:tree.php”);
  echo  “<script
language=’javascript’>alert(‘编辑成功!’);window.location=’tree.php'</script>”;
        exit;
  }
  break;
 case del:
  $sql=”delete from tvmenu where id=’$b'”;
    $qu=mysql_query($sql,$conn);
  if($qu){
  $del=””;
  echo  “<script
language=’javascript’>alert(‘删除成功!’);window.location=’tree.php'</script>”;
  exit;
  }
 }
?>

  function query($sql){

<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en”
“;
<html xmlns=”;
<head>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″
/>
<head>
<style
type=”text/css教程”>
<!–
.menu { color:#000000; font-size: 12px; cursor: hand;}
</style>
<script
type=”text/网页特效”>
function showmenu(menuid)
 {
 if(menuid.style.display==”none”)
 {
 menuid.style.display=””;
 }
 else
 {
 menuid.style.display=”none”;
 }
 }
</script>
<title>电视机树状目录</title>
</head>
<body>
<?php
 $globals[“id”] =1;
 $jibie=1;
 $sql=”select * from tvmenu where bid=0″;
 $result=mysql教程_query($sql,$conn);
 
 if(mysql_num_rows($result)>0)
 treemenu($conn,$result,$jibie,$id);
 
 function treemenu($conn,$result,$jibie)  //步入函数循环
 {
 $numrows=mysql_num_rows($result);
 echo “<table cellpadding=’0′ cellspacing=’0′ border=’0′>”;
 for($rows=0;$rows<$numrows;$rows++)
 {
 $menu=mysql_fetch_array($result);
 $sql=”select * from tvmenu where bid=$menu[id]”;
 $result_sub=mysql_query($sql,$conn);
 echo “<tr>”;
  //固然该菜单系列有子菜单,则增加javascript onclick语句
  if(mysql_num_rows($result_sub)>0)
  {
  echo “<td width=’20’><img src=’+.gif’
border=’0′></td>”;
  echo “<td class=’menu’
onclick=’javascript:showmenu(menu”.$globals[“id”].”);’>”;
  }
  else
  {
  echo “<td width=’20’><img src=’-.gif’
border=’0′></td>”;
  echo “<td class=’menu’>”;
  }
  if($menu[url]!=””)
  echo “<a href=’$menu[url]’>$menu[name]</a> “;
  else
  echo “<a href=’#’>$menu[name]</a>   <a
href=’?b={$menu[id]}&tpye=add’> 添加</a>  <a
href=’?b={$menu[id]}&tpye=edit’> 编辑</a>  <a
href=’?b={$menu[id]}&action=del’> 删除</a>”;
  echo “</td> </tr>”;
  if(mysql_num_rows($result_sub)>0)
  {
  echo “<tr id=menu”.$globals[“id”]++.”
style=’display:none’>”;
  echo “<td width=’20’> </td>”;
  echo “<td>”;
  //将级数加1
  $jibie++;
  treemenu($conn,$result_sub,$jibie);
  $jibie–;
  echo “</td></tr>”;
  }
  //显示下一菜单
  }
  echo “</table>”;
}
?>
<br />
<br />
<?php if ($tpye==”add”) { ?>
<table width=”551″ border=”0″ cellpadding=”0″ cellspacing=”1″
bgcolor=”#cccccc”>
<form action=”” method=”post” name=”form1″>
  <tr>
    <td height=”28″ colspan=”2″ align=”center”
bgcolor=”#ffffff”>增添栏目</td>
  </tr>
  <tr>
    <td width=”246″ height=”28″ align=”right”
bgcolor=”#ffffff”>栏目名称:</td>
    <td width=”302″ height=”28″ bgcolor=”#ffffff”><input
name=”name” type=”text” id=”name” /></td>
  </tr>
  <tr>
    <td height=”28″ align=”right”
bgcolor=”#ffffff”>所属分类:</td>
    <td height=”28″ bgcolor=”#ffffff”><select name=”bid”>
<?php
   
 $sql=”select * from tvmenu”;
 $que=mysql_query($sql,$conn);
    while($rs=mysql_fetch_array($que)){
  if ($rs[‘id’]==$b) {
     $selected=”selected=”selected””;
     }else{
     $selected=””;
     }
 ?>
 
      <option value=”<?php echo $rs[“id”]; ?>” <?php echo
$selected;?>><?php echo $rs[“name”]; ?></option>
  <?php }?>
    </select>
    </td>
  </tr>
  <tr>
    <td height=”28″ colspan=”2″ align=”center”
bgcolor=”#ffffff”><input type=”submit” name=”submit” value=”提
交” /></td>
  </tr>
  </form>
</table>
<?php }?>

  }

 代码如下

<body>
<a href=”add.php”>发表留言</a>
<?php
require(‘common.php’);
$result =
mysql教程_query(“select
* from gb_content order by id desc”);//查询数据

— 表的构造 `tvmenu`

create table if not exists `tvmenu` (
  `id` tinyint(4) not null auto_increment,
  `bid` tinyint(4) not null default ‘0’,
  `name` varchar(20) default null,
  `url` varchar(60) default null,
  primary key  (`id`)
) engine=innodb  default charset=utf8 auto_increment=16 ;