具体内容如下。
''''''''''''''''''''''
add.php
'''''''''''''''''''''''''''
<?php include "config.inc.php"; ?>
<html><head>
<title>添加文章</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="common.css">
<script language="JavaScript">
<!--
function Juge(theForm)
{
if (theForm.title.value == "")
{
alert("请输入标题!");
theForm.title.focus();
return (false);
}
if (theForm.subkey.value == "" && theForm.newsubkey.value == "")
{
alert("请选择分类!");
theForm.detail.focus();
return (false);
}
if (theForm.detail.value == "")
{
alert("请输入内容!");
theForm.detail.focus();
return (false);
}
}
//-->
</script>
</head><body bgcolor="#FFFFFF"><p align="center">添加文章</p>
<form name="form1" method="post" action="add_ok.php" onsubmit="javascript:return Juge(this);">
<div align="center">
<center>
<table border="0">
<tr>
<td width="100%" nowrap>标 题:<input type="text" name="title" size="60" maxlength="80"><br>
分 类:<select size="1" name="subkey">
<option selected>--请选择--</option>
<?php
$sqldo="select * from categorys order by name desc";
$result=mysql_query($sqldo);
if($result){
$rows=mysql_num_rows($result);
while($myrow=mysql_fetch_array($result)){
echo " <option value=\"$myrow[name]\">$myrow[name]</option>\n";
}
}
?>
</select> 或新建:<input type="text" name="newsubkey" size="20"><br>
<?php
$d_year=date("Y");
$d_month=date("m");
$d_day=date("d");
echo " 来 源:<input type=\"text\" name=\"source\" size=\"26\"> 添加时间:<input type=\"text\" name=\"d_year\" size=\"4\" value=$d_year>年<input type=\"text\" name=\"d_month\" size=\"2\" value=$d_month>月<input type=\"text\" name=\"d_day\" size=\"2\" value=$d_day>日<br>\n";
?>
内 容:<br>
<textarea name="detail" rows="10" cols="68"></textarea><br>
<input type="submit" name="add" value="提交"> <input type="reset" value="重填"> <input type="button" value="返回" onClick="history.back()"></td>
</tr>
</table>
</center>
</div>
</form></body></html>
''''''''''''''''''''
add_ok.php'''''''''''''''''''''
<?php include "config.inc.php"; ?>
<html>
<head>
<title>提交成功</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<body bgcolor=#FFFFFF>
<?php
if ($add){ $title=htmlspecialchars($title);
$mainkey=htmlspecialchars($mainkey);
$subkey=htmlspecialchars($subkey);
$source=htmlspecialchars($source);
$detail=htmlspecialchars($detail);
// $detail= str_replace ( "\n","<br>", $detail);
if (checkdate($d_month,$d_day,$d_year) && $title) {
if ($newsubkey){
$newsubkey=htmlspecialchars($newsubkey);
$subkey=$newsubkey;
// $sqldo="insert into categorys (name) values ('$subkey')";
// $result=mysql_query($sqldo);
}
$add_time=$d_year."-".$d_month."-".$d_day." ".date("H").":".date("i").":".date("s");
$sqldo="insert into $temptable (title,detail,add_time,mainkey,subkey,source) values ";
$sqldo.="('$title','$detail','$add_time','$mainkey','$subkey','$source')";
$result=mysql_query($sqldo);
}
else {
$result=0;
$myerror = "日期错误!";
} echo "<div align='center'>";
if ($result){
echo "<p>提交成功!谢谢!如果内容有价值,管理员将会很快予以正式发布!<br><br>[ <a href='$homepage'>首页</a> <a href='$homepage?viewnew=1'>查看</a> <a href='add.php'>发布</a> ]</p>";
}
else{
echo mysql_error();
echo "<p>提交失败!$myerror <A href=\"JavaScript:history.back()\">返回</A></p>";
}
echo "</div>";
}
?>
</body>
</html>
谢谢你们回答
''''''''''''''''''''''
add.php
'''''''''''''''''''''''''''
<?php include "config.inc.php"; ?>
<html><head>
<title>添加文章</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="common.css">
<script language="JavaScript">
<!--
function Juge(theForm)
{
if (theForm.title.value == "")
{
alert("请输入标题!");
theForm.title.focus();
return (false);
}
if (theForm.subkey.value == "" && theForm.newsubkey.value == "")
{
alert("请选择分类!");
theForm.detail.focus();
return (false);
}
if (theForm.detail.value == "")
{
alert("请输入内容!");
theForm.detail.focus();
return (false);
}
}
//-->
</script>
</head><body bgcolor="#FFFFFF"><p align="center">添加文章</p>
<form name="form1" method="post" action="add_ok.php" onsubmit="javascript:return Juge(this);">
<div align="center">
<center>
<table border="0">
<tr>
<td width="100%" nowrap>标 题:<input type="text" name="title" size="60" maxlength="80"><br>
分 类:<select size="1" name="subkey">
<option selected>--请选择--</option>
<?php
$sqldo="select * from categorys order by name desc";
$result=mysql_query($sqldo);
if($result){
$rows=mysql_num_rows($result);
while($myrow=mysql_fetch_array($result)){
echo " <option value=\"$myrow[name]\">$myrow[name]</option>\n";
}
}
?>
</select> 或新建:<input type="text" name="newsubkey" size="20"><br>
<?php
$d_year=date("Y");
$d_month=date("m");
$d_day=date("d");
echo " 来 源:<input type=\"text\" name=\"source\" size=\"26\"> 添加时间:<input type=\"text\" name=\"d_year\" size=\"4\" value=$d_year>年<input type=\"text\" name=\"d_month\" size=\"2\" value=$d_month>月<input type=\"text\" name=\"d_day\" size=\"2\" value=$d_day>日<br>\n";
?>
内 容:<br>
<textarea name="detail" rows="10" cols="68"></textarea><br>
<input type="submit" name="add" value="提交"> <input type="reset" value="重填"> <input type="button" value="返回" onClick="history.back()"></td>
</tr>
</table>
</center>
</div>
</form></body></html>
''''''''''''''''''''
add_ok.php'''''''''''''''''''''
<?php include "config.inc.php"; ?>
<html>
<head>
<title>提交成功</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<body bgcolor=#FFFFFF>
<?php
if ($add){ $title=htmlspecialchars($title);
$mainkey=htmlspecialchars($mainkey);
$subkey=htmlspecialchars($subkey);
$source=htmlspecialchars($source);
$detail=htmlspecialchars($detail);
// $detail= str_replace ( "\n","<br>", $detail);
if (checkdate($d_month,$d_day,$d_year) && $title) {
if ($newsubkey){
$newsubkey=htmlspecialchars($newsubkey);
$subkey=$newsubkey;
// $sqldo="insert into categorys (name) values ('$subkey')";
// $result=mysql_query($sqldo);
}
$add_time=$d_year."-".$d_month."-".$d_day." ".date("H").":".date("i").":".date("s");
$sqldo="insert into $temptable (title,detail,add_time,mainkey,subkey,source) values ";
$sqldo.="('$title','$detail','$add_time','$mainkey','$subkey','$source')";
$result=mysql_query($sqldo);
}
else {
$result=0;
$myerror = "日期错误!";
} echo "<div align='center'>";
if ($result){
echo "<p>提交成功!谢谢!如果内容有价值,管理员将会很快予以正式发布!<br><br>[ <a href='$homepage'>首页</a> <a href='$homepage?viewnew=1'>查看</a> <a href='add.php'>发布</a> ]</p>";
}
else{
echo mysql_error();
echo "<p>提交失败!$myerror <A href=\"JavaScript:history.back()\">返回</A></p>";
}
echo "</div>";
}
?>
</body>
</html>
谢谢你们回答
if($add){
$put1=$put;
echo "$put";}
else{
echo "没有值!";}
?>
不改也可以,采用新的写法,提交表单的接收方式为:$_POST['变量名']
if($add){
$put1=$_POST['$put'];
echo "$put1";}
else{
echo "没有值!";}
?>