请教编程思路!

kitling 2003-06-25 07:29:29
本人刚学php,要编写一个文章发布的页面,有一组单选钮(A、B两个),一个单行文本输入和一个多行文本输入。

当选A时(默认),页面与这里的提问页面大致相同,当选B时,将在原有页面基础上增加新的内容,比如一行文本。

我在单选钮上编了一个js的onclick的响应函数,这个函数把单选钮的选项,单行文本的值和多行文本的值记录到cookie中,然后刷新。

在php页面中用if判断一下cookie中的值,以便在刷新后还能保持不变。

以上内容已实现,但当多行文本内容太多时,cookie存不下,当刷新后多行文本内容出错。

我打算用数据库实现多行文本的暂时记录,但这又影响速度,不知道各位是否遇到过这样的问题,请告知是如何实现的。

源代码如下,请各位高手指教,谢谢:)

-----------------------------------
<?php
if(!isset($userselect))
setcookie("userselect","1");
if(!isset($uflag))
setcookie("uflog","0");
?>
<html>

<script language="javascript">
<!--
function openwin() {
wins=open('overloadimage.php','WINTS','toolbar=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=420');
}

function refresh(number){
var days = 1;
var expdate = new Date();

expdate.setTime (expdate.getTime() + 1000 );
document.cookie = "userselect =" + number + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "usertitle =" + document.F1.T1.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userclass =" + document.F1.D1.selectedIndex + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "usertext =" + document.F1.S1.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userrelation =" + document.F1.T2.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userquote =" + document.F1.T3.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userauthor =" + document.F1.T4.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "uflag = 1 ; expires=" + expdate.toGMTString() + ";";
window.location.reload();
}

//-->
</script>


<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>新闻模板--增加新闻</title>
<link rel="stylesheet" type="text/css" href="css.css">
</head>

<body>

<form method="POST" action="post.php" name="F1">

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="305">
<tr>
<td width="100%" colspan="2" bgcolor="#A6CA27" height="24">
<p align="center"><b><font size="2" color=#ffffff>增 加 新 闻</font></b></td>
</tr> <tr>
<td width="15%" align="right" height="24" valign="top">文章类型(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24">

<?php

include("newstype.php");
?>

<font color="#CC0033">        请先选择此项,否则更新页面时将清除其它输入的内容!</font>
</td>
</tr>
<tr>
<td width="15%" align="right" height="30">文章标题(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="30">

<?php
if($_COOKIE['uflag']==0)
echo ' <input type="text" name="T1" size="50" style="background-color:ffffff;color:000000;border: 1 double" maxlength="120">';
else{
echo ' <input type="text" name="T1" size="50" value="'.$_COOKIE['usertitle'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="120">';
}

?>
<font color=#CC0033>    标题请不要超过60个汉字!</font> </td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">文章分类(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24">
 <select size="1" name="D1">
<?php
include("newsclass.php");
?>
</select>

</td>
</tr>

<tr>
<td width="15%" align="right" height="24" valign="top">文章内容(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24"> 

<?php
if($_COOKIE['uflag']==0)
echo '<textarea rows="23" name="S1" cols="77"></textarea>';
else
echo '<textarea rows="23" name="S1" cols="77">'.$_COOKIE['usertext'].'</textarea>';
?>

</td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top"> </td>
<td width="85%" valign="middle" height="24"><font color="#CC0033"> 本系统支
持多种格式修饰功能,请参阅<a href="formathelp.htm">帮助</a>。</font></td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">相关新闻:</td>
<td width="85%" valign="middle" height="24"> 
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T2" size="50" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
else
echo '<input type="text" name="T2" size="50" value="'.$_COOKIE['userrelation'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
?>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top"> </td>
<td width="85%" valign="middle" height="24"><font color="#CC0033"> 相关新闻只需输入关键字或完整标题,关键字之间请用西文状态下的分号(;)分开,总长不得超过25个汉字</font></td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">来源:</td>
<td width="85%" valign="middle" height="24"> 
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T3" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
else
echo '<input type="text" name="T3" size="16" value="'.$_COOKIE['userquote'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
?>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">文章作者:</td>
<td width="85%" valign="middle" height="24"> 
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T4" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="12">';
else
echo '<input type="text" name="T4" value="'.$_COOKIE['userauthor'].'" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="12">';
?>
</td>
</tr>




<?php
if ($_COOKIE['userselect']==2){

echo "<tr>";
echo '<td width="100%" align="center" height="24" valign="top" colspan="2"> <input type="button" value="上传本地图片..." name="B3" class="mface" OnClick=openwin()></td>';
echo "</tr>";
echo "<tr>";
echo '<td width="100%" align="center" height="24" colspan="2">';
echo '<font color="#CC0033">上传本地图片是使用了[img]n[/img](其中n为1、2...)方式时所必须使用的,使用[img]http://...[/img]方式时不用使用此项</font></td>';
echo "</tr>";
}
?>

<tr>
<td width="100%" align="center" height="24" colspan="2">
<font color="#CC0033">代(*)的项目必须有内容<br>新闻增加后还不能立即发表,需等待审核后,才可在新闻中心看到,如出现发布问题请与审核员联系</font></td>
</tr>
<tr>
<td width="100%" align="center" height="24" colspan="2"> 
<input type="submit" value=" 提 交 "
name="cmdok" class="mface">
 
<input type="reset" value=" 清 除 "
name="cmdcancel" class="mface">
<p><font color="#CC0033">如有技术问题,请与管理员联系</font></td>
</tr>
</table>
</form>
</body>

</html>
...全文
43 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2003-06-26
  • 打赏
  • 举报
回复
为什么不用"提交"
kitling 2003-06-26
  • 打赏
  • 举报
回复
没什么技巧啊,全都是一些简单的语句,另外我是一个比较懒的人:)

帮我看看文字吧,代码只是怕看不懂文字时参考的:)

谢谢,对不起费眼睛了:)
bbrr 2003-06-26
  • 打赏
  • 举报
回复
晕!这么长的问题也好意思提出来。你应该尽量提一些关键的问题!又长又臭谁看的下去!!!!!!
wuqing1113 2003-06-25
  • 打赏
  • 举报
回复
呵呵 是啊 我看不懂的 很深啊呵呵
vitalgg 2003-06-25
  • 打赏
  • 举报
回复
这么长,一句注释也没有!:(
kitling 2003-06-25
  • 打赏
  • 举报
回复
------------------------------------
newstype.php

<?php
$db=mysql_connect("localhost","root");

$query="SELECT * FROM newstype order by id asc";

$result=mysql_db_query("tcbuudb",$query);


$num=1;

while($r=mysql_fetch_array($result))
{
$str=$r["typename"];
echo '<input type="radio" value="'.$num.'" name="R1" ';

if($num==$_COOKIE['userselect'])
echo "checked";
echo ' OnClick=refresh('.$num.$T1.$D1.$S1.$T2.$T3.$T4.')>' .$str. "     ";
$num+=1;

}
mysql_close($db);
?>

---------------------------------
newsclass.php


<?php
$db=MySQL_connect("localhost","root");
MySQL_select_db("tcbuudb",$db);
$result=MySQL_query("SELECT * FROM newsclass order by id asc",$db);
$nnn=0;
while($myclass=MySQL_fetch_array($result))
{
$str=$myclass["classname"];
if($_COOKIE['userclass']==$nnn)
echo "<option selected> $str";
else
echo "<option> $str";
$nnn+=1;
}

mysql_close($db);
?>

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧