用php写了一个简单的发布信息页面,上传完图片后页面会自动刷新,之前表单中填写的内容就全没了,怎么让上传完成后还能保留表单中的内容
希望能帮忙解决
<?php
session_start();
include("config.php");
$myselect1 = -1;
$username3=$HTTP_SESSION_VARS["id"];
$title1=$HTTP_POST_VARS["title"];
$content1=$HTTP_POST_VARS["content"];
$myselect1=$HTTP_POST_VARS["myselect"];
$buy_or_sell=$HTTP_POST_VARS["radio"];
$withimg1=$HTTP_POST_VARS["withimg"];
if($withimg1 == "withimg")
{
$withimg1 = "1";
}
else
{
$withimg1 = "0";
}
$_SESSION['withimg']=$withimg1;
date_default_timezone_set(PRC);
$savetime =date("d-m-y G:i");
//上传部分
if($_POST['upload']){ if (is_uploaded_file($_FILES['upfile']['tmp_name'])){$upfile=$_FILES["upfile"];$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
$error = $upfile["error"];
//echo $name;
$_SESSION['imgsrc']=$name;
//echo $_SESSION['imgsrc'];
switch ($type) {
case 'image/pjpeg' : $ok=1;
break;
case 'image/jpeg' : $ok=1;
break;
case 'image/gif' : $ok=1;
break;
case 'image/png' : $ok=1;
break;
}if($ok && $error=='0'){
move_uploaded_file($tmp_name,'up/'.$name);
echo "<script language=\"javascript\">alert('上传成功,请选中有图片后填写信息内容!');window.location.href='sendmessage.php';</script>";
}
}
}
if($_POST['submit']){ if($buy_or_sell=="sell"){
$query1 = "insert into mes_".$username3." (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked)" .
" values ('$username3','sendsell','$myselect1','$title1','$content1','$savetime' ,'checkman','checking')";
$result=@mysql_query($query1)or die("未插入个人信息表成功!");
if($result) {echo "<script language=\"javascript\">alert('发布成功');window.location.href='showsendmessagetitle.php';</script>";}
$result1 = mysql_query("select max(messageid) maxid from mes_".$username3) or die("选择messageid错误");
$row = mysql_fetch_array($result1);
$query2 = "insert into `all_message` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked,user_tableid)" .
" values ('$username3','sendsell','$myselect1','$title1','$content1','$savetime' ,'checkman','checking','$row[maxid]')";
$result=@mysql_query($query2)or die("未插入总信息表成功!");
}
if($buy_or_sell=="buy"){
$query1 = "insert into `mes_".$username3."` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked)" .
" values ('$username3','sendbuy','$myselect1','$title1','$content1','$savetime' ,'checkman','checking')";
$result=@mysql_query($query1)or die("未插入个人信息表成功!");
if($result) {echo "<script language=\"javascript\">alert('发布成功');window.location.href='showsendmessagetitle.php';</script>";}
$result1 = mysql_query("select max(messageid) maxid from mes_".$username3) or die("选择messageid错误");
$row = mysql_fetch_array($result1);
$query2 = "insert into `all_message` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked,user_tableid)" .
" values ('$username3','sendbuy','$myselect1','$title1','$content1','$savetime' ,'checkman','checking','$row[maxid]')";
$result=@mysql_query($query2)or die("未插入总信息表成功!");
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>发布信息</title>
<SCRIPT language=javascript>
function CheckPost()
{
if (form1.title.value=="")
{
alert("标题不能为空");
form1.title.focus();
return false;
}
if (form1.content.value=="")
{
alert("内容不能为空");
form1.content.focus();
return false;
}
if (form1.myselect.value=="-1")
{
alert("请选择分类");
form1.myselect.focus();
return false;
}
}
</SCRIPT>
<style>
#header{
width:900px;
height:40px;
}
#showmenu {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
float:left;
}
#showmenu a,#showmenu a:visited {
display:block;
width:10em;
padding:0.25em;
margin:0.5em auto;
color:#fff;
text-decoration:none;
text-align:center;
background-color:#8ab;
border:2px solid #fff;
border-color:#def #678 #345 #cde;
position:relative;
}
#showmenu a:hover {
top:2px;
left:2px;
border-color:#345 #cde #def #678;
}
}
#showbody {
width:980px;
height:200px;
}
#showleft {
width:200px;
height:200px;
float:left;
padding:20px;
}
#showright {
width:700px;
height:200px;
float:right;
padding-top:35px;
}
</style>
</head>
<body>
<div id="header">
<table align="left" width="900px" height="40px">
<tr>
<td width="20%" align="left" style="margin-left=20px">
用户名:<a href="showperinformation.php"><?php $username3=$_SESSION['id']; echo $username3;?>
</a></td>
<td width="5%" align="center"><a href="logoff.php"><font size="-1">注销</font></td>
<td width="15%" align="center"><a href="showperinformation.php">个人信息</a></td><td width="15%" align="center"><a href="sendmessage.php">信息管理</a></td>
<td width="15%" align="center"><a href="sendmessage.php">公告管理</a></td>
<td width="15%" align="center"><a href="waitcheckmessage.php">信息审核</a></td><td width="15%" align="center"><a href="#">用户管理</a></td>
</tr>
</table>
</div>
<div id = "showbody">
<div id = "showleft">
<div id="showmenu">
<a href="showperinformation.php"> 个人信息 </a>
<a href="sendmessage.php"> 发布信息 </a>
<a href="showsendmessagetitle.php"> 发件箱管理 </a>
<a href="showreceivedmessagetitle.php"> 收件箱管理 </a>
</div>
</div>
<div id = "showright">
<form name="form1" method="post" action="sendmessage.php" onsubmit="return CheckPost();"><h1>发布信息</h1><br />
<p>信息标题: <input name="title" type="text" id="nickname">
<input name="withimg" type="checkbox" value="withimg">有图片
<input type="radio" name="radio" value="buy" >我想买
<input type="radio" name="radio" value="sell" checked>我想卖
<br /><br />
信息内容:<br />
<textarea name="content" cols="70" rows="20" style="margin-left:83px; margin-top:-15px;"></textarea><br /><br />
信息分类:<select name="myselect" id="myselect" style="float:left; margin-left:80px; margin-top:-20px;">
<option value="-1">----请选择----</option>
<option value ="1">财经类图书信息</option>
<option value ="2">文学类图书信息</option>
<option value="3">计算机类图书信息</option>
<option value="4">工具类图书信息</option>
<option value="5">英语类图书信息</option>
<option value="6">其他类图书信息</option>
<option value="51">二手货信息信息</option>
<option value="61">房屋租赁信息</option>
<option value="71">招领类信息信息</option>
<option value="91">招聘类信息</option>
</select><br>
<input type="submit" name="submit" value="发布信息" style="float:left; margin-left:350px; margin-top:10px;"><br/><br></p></form>
<form name="form2" method="post" action="sendmessage.php" enctype="multipart/form-data" >
上传图片:
<input name="upfile" type="file">
<input type="submit" name="upload" value="上传"><br></form></div>
</div>
</body>
</html>
希望能帮忙解决
<?php
session_start();
include("config.php");
$myselect1 = -1;
$username3=$HTTP_SESSION_VARS["id"];
$title1=$HTTP_POST_VARS["title"];
$content1=$HTTP_POST_VARS["content"];
$myselect1=$HTTP_POST_VARS["myselect"];
$buy_or_sell=$HTTP_POST_VARS["radio"];
$withimg1=$HTTP_POST_VARS["withimg"];
if($withimg1 == "withimg")
{
$withimg1 = "1";
}
else
{
$withimg1 = "0";
}
$_SESSION['withimg']=$withimg1;
date_default_timezone_set(PRC);
$savetime =date("d-m-y G:i");
//上传部分
if($_POST['upload']){ if (is_uploaded_file($_FILES['upfile']['tmp_name'])){$upfile=$_FILES["upfile"];$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
$error = $upfile["error"];
//echo $name;
$_SESSION['imgsrc']=$name;
//echo $_SESSION['imgsrc'];
switch ($type) {
case 'image/pjpeg' : $ok=1;
break;
case 'image/jpeg' : $ok=1;
break;
case 'image/gif' : $ok=1;
break;
case 'image/png' : $ok=1;
break;
}if($ok && $error=='0'){
move_uploaded_file($tmp_name,'up/'.$name);
echo "<script language=\"javascript\">alert('上传成功,请选中有图片后填写信息内容!');window.location.href='sendmessage.php';</script>";
}
}
}
if($_POST['submit']){ if($buy_or_sell=="sell"){
$query1 = "insert into mes_".$username3." (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked)" .
" values ('$username3','sendsell','$myselect1','$title1','$content1','$savetime' ,'checkman','checking')";
$result=@mysql_query($query1)or die("未插入个人信息表成功!");
if($result) {echo "<script language=\"javascript\">alert('发布成功');window.location.href='showsendmessagetitle.php';</script>";}
$result1 = mysql_query("select max(messageid) maxid from mes_".$username3) or die("选择messageid错误");
$row = mysql_fetch_array($result1);
$query2 = "insert into `all_message` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked,user_tableid)" .
" values ('$username3','sendsell','$myselect1','$title1','$content1','$savetime' ,'checkman','checking','$row[maxid]')";
$result=@mysql_query($query2)or die("未插入总信息表成功!");
}
if($buy_or_sell=="buy"){
$query1 = "insert into `mes_".$username3."` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked)" .
" values ('$username3','sendbuy','$myselect1','$title1','$content1','$savetime' ,'checkman','checking')";
$result=@mysql_query($query1)or die("未插入个人信息表成功!");
if($result) {echo "<script language=\"javascript\">alert('发布成功');window.location.href='showsendmessagetitle.php';</script>";}
$result1 = mysql_query("select max(messageid) maxid from mes_".$username3) or die("选择messageid错误");
$row = mysql_fetch_array($result1);
$query2 = "insert into `all_message` (username,messageAttribute,messageClassify,messageTitle,messageContent,time,receivefrom,ischecked,user_tableid)" .
" values ('$username3','sendbuy','$myselect1','$title1','$content1','$savetime' ,'checkman','checking','$row[maxid]')";
$result=@mysql_query($query2)or die("未插入总信息表成功!");
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>发布信息</title>
<SCRIPT language=javascript>
function CheckPost()
{
if (form1.title.value=="")
{
alert("标题不能为空");
form1.title.focus();
return false;
}
if (form1.content.value=="")
{
alert("内容不能为空");
form1.content.focus();
return false;
}
if (form1.myselect.value=="-1")
{
alert("请选择分类");
form1.myselect.focus();
return false;
}
}
</SCRIPT>
<style>
#header{
width:900px;
height:40px;
}
#showmenu {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
float:left;
}
#showmenu a,#showmenu a:visited {
display:block;
width:10em;
padding:0.25em;
margin:0.5em auto;
color:#fff;
text-decoration:none;
text-align:center;
background-color:#8ab;
border:2px solid #fff;
border-color:#def #678 #345 #cde;
position:relative;
}
#showmenu a:hover {
top:2px;
left:2px;
border-color:#345 #cde #def #678;
}
}
#showbody {
width:980px;
height:200px;
}
#showleft {
width:200px;
height:200px;
float:left;
padding:20px;
}
#showright {
width:700px;
height:200px;
float:right;
padding-top:35px;
}
</style>
</head>
<body>
<div id="header">
<table align="left" width="900px" height="40px">
<tr>
<td width="20%" align="left" style="margin-left=20px">
用户名:<a href="showperinformation.php"><?php $username3=$_SESSION['id']; echo $username3;?>
</a></td>
<td width="5%" align="center"><a href="logoff.php"><font size="-1">注销</font></td>
<td width="15%" align="center"><a href="showperinformation.php">个人信息</a></td><td width="15%" align="center"><a href="sendmessage.php">信息管理</a></td>
<td width="15%" align="center"><a href="sendmessage.php">公告管理</a></td>
<td width="15%" align="center"><a href="waitcheckmessage.php">信息审核</a></td><td width="15%" align="center"><a href="#">用户管理</a></td>
</tr>
</table>
</div>
<div id = "showbody">
<div id = "showleft">
<div id="showmenu">
<a href="showperinformation.php"> 个人信息 </a>
<a href="sendmessage.php"> 发布信息 </a>
<a href="showsendmessagetitle.php"> 发件箱管理 </a>
<a href="showreceivedmessagetitle.php"> 收件箱管理 </a>
</div>
</div>
<div id = "showright">
<form name="form1" method="post" action="sendmessage.php" onsubmit="return CheckPost();"><h1>发布信息</h1><br />
<p>信息标题: <input name="title" type="text" id="nickname">
<input name="withimg" type="checkbox" value="withimg">有图片
<input type="radio" name="radio" value="buy" >我想买
<input type="radio" name="radio" value="sell" checked>我想卖
<br /><br />
信息内容:<br />
<textarea name="content" cols="70" rows="20" style="margin-left:83px; margin-top:-15px;"></textarea><br /><br />
信息分类:<select name="myselect" id="myselect" style="float:left; margin-left:80px; margin-top:-20px;">
<option value="-1">----请选择----</option>
<option value ="1">财经类图书信息</option>
<option value ="2">文学类图书信息</option>
<option value="3">计算机类图书信息</option>
<option value="4">工具类图书信息</option>
<option value="5">英语类图书信息</option>
<option value="6">其他类图书信息</option>
<option value="51">二手货信息信息</option>
<option value="61">房屋租赁信息</option>
<option value="71">招领类信息信息</option>
<option value="91">招聘类信息</option>
</select><br>
<input type="submit" name="submit" value="发布信息" style="float:left; margin-left:350px; margin-top:10px;"><br/><br></p></form>
<form name="form2" method="post" action="sendmessage.php" enctype="multipart/form-data" >
上传图片:
<input name="upfile" type="file">
<input type="submit" name="upload" value="上传"><br></form></div>
</div>
</body>
</html>
解决方案 »
- div+css
- 播放器问题
- PHP判断页面传入参数是否合法
- 怎么用php使用本机固定端口和sqlserver服务器相连接
- 用php实现自动截取swf中某一秒的截图?急,急,急,急
- Linux上面跑的PHP....一次只能设置一个Cookie,究竟如何解决
- 我的zendStudioClient2.6.2还有五天过期了,谁有registration name 和license name
- 我用win2k,下载了php4.3.1,extension_dir是c:\php\ext 可是里面没有php_gd.dll,怎么办,到哪里可以down一个补上?
- 怎么样写程序直接显示当前目录下的图片的缩略图?
- 我的程序根本就没有60行,可是报错说60行出错。请问这是什么原因啊?
- 再次提问,关于反向代理的若干问题
- 分页代码怎么老是出现警告,达人们进来看看代码....
把这个值写到input 中的value
所以加个判断是否提交了,如果提交了,就是post的值,否则就是空值啊。
<p>信息标题: <input name="title" type="text" id="nickname" value="<?php echo $title1; ?>">
$content1=$HTTP_POST_VARS["content"]; $myselect1=$HTTP_POST_VARS["myselect"]; 这三步能把title和content取出来吗