<?php
/*******所用到的表结构********
drop table if exists index_news;
create table index_news (
news_id bigint(20) not null auto_increment,
news_date date default 0000-00-00 not null,
news_title varchar(100) not null,
news_content text,
news_link varchar(100),
is_new char(1) default 1,
picture_id int(11),
picture_side char(1) default 1,
news_show char(1) default 1,
primary key (news_id),
key id (news_id)
);
drop table if exists picture;
create table picture (
id int(11) not null auto_increment,
picture blob not null,
picture_type varchar(50) not null,
primary key (id),
unique id (id)
);
**********************/
require("../include/date.inc.php3");
require("../include/config.inc.php3");
?>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>修改首页新闻信息</title>
<script language="javascript">
<!–
function mm_findobj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexof("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=mm_findobj(n,d.layers[i].document); return x;
}
function mm_validateform() { //v3.0
var i,p,q,nm,test,num,min,max,errors=,args=mm_validateform.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; obj_name=args[i+1]; val=mm_findobj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexof(isemail)!=-1) { p=val.indexof(@);
if (p<1 || p==(val.length-1)) errors+=- +obj_name+ 必须是一个e-mail地址.\n;
} else if (test!=r) { num = parsefloat(val);
if (val!=+num) errors+=- +obj_name+ 必须是一个数字.\n;
if (test.indexof(inrange) != -1) { p=test.indexof(:);
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+=- +obj_name+ 必须是一个在 +min+ 和 +max+之间的数字.\n;
} } } else if (test.charat(0) == r) errors += – +obj_name+ 必须输入.\n; }
} if (errors) alert(输入数据存在错误:\n+errors);
document.mm_returnvalue = (errors == );
}
//–>
</script>
</head>
<body>
<?php
if ($add){
$date=input2date($news_date);
//echo $picture . " ". filesize($picture);
//if ($is_new!="0") $is_new="1" ;
//if ($news_show!="0") $news_show="1";
//if ($picture_side!="2") $picture_side="1";
if ($picture!="none"){
$pic_data = addslashes(fread($fp=fopen($picture,"r"), filesize($picture)));
$i_str="insert into picture (picture,picture_type) values ($pic_data,$picture_type)";
//$rs->open($i_str);
$result=mysql_query($i_str,$dbconnect);
$picture_id=mysql_insert_id();
fclose($fp);
unlink($picture);
}
else{
$picture_id=0 ;
}
$i_str="insert into index_news (news_date,news_title,news_content,news_link,picture_id,is_new,picture_side,news_show) values ";
$i_str.="($date,$news_title,$news_content,$news_link,$picture_id,$is_new,$picture_side,$news_show) ";
if (mysql_query($i_str,$dbconnect)) echo "已添加!";
}
<form name="f" enctype="multipart/form-data" method="post" action="<?php echo $path_info; ?>" >
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="2">
<div align="center"><font size="4">增加新闻信息</font></div>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="100">新闻标题: </td>
<td>
<input type="text" name="news_title" size="60">
</td>
</tr>
<tr>
<td>新闻内容:</td>
<td>
<textarea name="news_content" cols="58" rows="5"></textarea>
</td>
</tr>
<tr>
<td>新闻日期:</td>
<td>
<input type="text" name="news_date">
(日期请按照2000-01-02格式输入) </td>
</tr>
<tr>
<td>新闻链接:</td>
<td>
<input type="text" name="news_link" size="60">
</td>
</tr>
<tr>
<td>是否最新:</td>
<td>
<select name="is_new">
<option value="1" selected>是最新</option>
<option value="0">不是最新</option>
</select>
</td>
</tr>
<tr>
<td>新闻图片:</td>
<td>
<input type="file" name="picture" size="50">
</td>
</tr>
<tr>
<td>图片位置:</td>
<td>
<select name="picture_side">
<option value="1" selected>左边</option>
<option value="2">右边</option>
</select>
</td>
</tr>
<tr>
<td>是否显示:</td>
<td>
<select name="news_show">
<option value="1" selected>显示</option>
<option value="0">不显示</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="add" value="增加" onclick="mm_validateform(news_title,,r,news_date,,r,news_content,,r);return document.mm_returnvalue">
<input type="button" name="return" value="返回">
<input type="reset" name="reset" value="重新输入">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>