Maison > Article > développement back-end > PHP 中的“新”字
PHP 新 奇葩
本人php新手 今天遇到个奇葩的问题 请求参数里 有“新”这个字贴出代码看下吧
做菜单栏部分代码
<div id="layerr12" style="display:none;"><table width="175" height="23" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli/list.php?wz=最新文章" target="forum">教育新闻</a></td> </tr> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli/list.php?wz=ejajo专栏" target="forum">ejajo专栏</a></td> </tr> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli1/list.asp" target="forum">资源共享</a></td> </tr> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli/list.php?wz=家长教育" target="forum">家长教育</a></td> </tr> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli/list.php?wz=心灵鸡汤" target="forum">心灵鸡汤</a></td> </tr> <tr> <td width="44" height="24"> </td> <td width="11" class="x1"> </td> <td width="120" class="bs">·<a href="infoli/list.php?wz=新公告" target="forum">最新公告</a></td> </tr> </table> </div>
<?php session_start(); require_once "../../inc/conn1.php";?><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head> <link href="../images/index.css" rel="stylesheet" type="text/css"><script type="text/javascript">function record_add(){ location.href='list_add.php?wz=<?php echo $_REQUEST["wz"];?>';}</script><?php $wz=$_REQUEST["wz"]; $key=$_REQUEST["key"]; $sql=" where 1=1"; if($wz!=""){ $query="wz='".$wz."'"; $sql=$sql." and wz='".$wz."'"; } if($key!=""){ $query="key ='".$key."'"; $sql=$sql." and title like '%".$key."%'"; } $sql="select * from info ".$sql." order by top desc,id desc"; $rs=new com("ADODB.RecordSet"); $rs->Open($sql,$conn,1,1); if($_REQUEST["page"]=="") $page=1; else $page=intval($_REQUEST["page"]); $i=0; $rs->pagesize=15; if($page<1) $page=1; if($page>$rs->pagecount) $page=$rs->pagecount; if($rs->pagecount>0) $rs->absolutepage=$page;?> <body onLoad="setupZoom();"><table width="102%" height="81%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="283" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"><form name="form1" method="post"> <tr> <td width="59" class="list black"> </td> <td width="500" class="list black">标 题</td> <td width="48" class="list black">序号</td> <td width="65" class="list black">点击</td> <td width="114" class="list black">类 别</td> <td width="102" class="list black">添加日期</td> <td width="111" class="list black">管理操作</td> </tr> <?php if($rs->eof) echo "<tr><td colspan='6' align='center'><font color='red'>系统中还没有录入相关任何信息!</font></td></tr>"; else while(!($rs->eof) and $i<$rs->pagesize) { //echo "<tr>";// echo "<td >1</td>";// echo "<td >2</td>"; // // echo "</tr>";// $rs->MoveNext(); ?> <tr onMouseOut="this.className=''" onMouseOver="this.className='list-bg'"> <td align="center" class="list1"><input type="checkbox" id="checkbox" value="<?php $rf=$rs->fields("id"); echo $rf->value;?>" name="checkbox[]" onClick="chkclick();"></td> <td class="list1 pl8"> <a href="List_Edit.asp?checkbox=<?php $rf=$rs->fields("id"); echo $rf->value;?>&wz=<?php echo $_REQUEST["wz"];?>"><?php $rf=$rs->fields("title");echo substr($rf->value,0,80);?></a> </td> <td align="center" class="list1" ><?php $rf=$rs->fields("top");echo $rf->value;?></td> <td align="center" class="list1"><?php $rf=$rs->fields("hit");echo $rf->value;?></td> <td align="center" class="list1"><?php $rf=$rs->fields("wz");echo substr($rf->value,0,15);?></td> <td align="center" class="list1 pl8"><?php $rf=$rs->fields("postdate");echo date("Y-m-d",$rf->value);?></td> <td align="center" class="list1 pl8"> <a href="List_Edit.php?checkbox=<?php $rf=$rs->fields("id"); echo $rf->value;?>">修改</a> | <a href="#" onClick="DelGood('<?php $rf=$rs->fields("id"); echo $rf->value;?>');">删除</a> </td> </tr><?php $rs->MoveNext(); }?> </form> </table> </td> </tr></table><table width="102%" border="0" cellpadding="0" cellspacing="0" background="../images/list_bottm_bg.gif"> <tr> <td width="16%" height="35" style="padding-left:8px;"> <input type=checkbox name='chkall' onClick='chooseall(document.form1.checkbox,this);'> 全选 <input type=checkbox name='chkl' onClick='choosefalse(document.form1.checkbox,this);'> 反选 </td> <td width="17%"><input name="Submit2" type="submit" class="submit" style="width:70px;" onClick="window.location.href='List_px.asp?wz=<?php echo $_REQUEST["wz"];?>'" value="信息排序"></td> <td width="67%"> </td> </tr></table><table width="102%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="2" colspan="3" bgcolor="#C1CBD0"></td> </tr> <tr> <td width="37%" height="39" background="../images/list_bottm_bg.gif"><table width="357" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td width="90"><input type="image" src="../images/list_bottm1.gif" onMouseOver="this.src='../images/list_bottm1h.gif'" onMouseOut="this.src='../images/list_bottm1.gif'" name="booot" onClick="history.go(0);" ></td> <td width="90"><input type="image" src="../images/list_bottm2.gif" onMouseOver="this.src='../images/list_bottm2h.gif'" onMouseOut="this.src='../images/list_bottm2.gif'" name="add" id="add" onClick="record_add();" ></td> <td width="90"><input type="image" src="../images/list_bottm3.gif" onMouseOver="this.src='../images/list_bottm3h.gif'" onMouseOut="this.src='../images/list_bottm3.gif'" onClick="record_edit();" name="edit" disabled ></td> <td width="90"><input type="image" src="../images/list_bottm4.gif" onMouseOver="this.src='../images/list_bottm4h.gif'" onMouseOut="this.src='../images/list_bottm4.gif'" onClick="record_del();" name="del" disabled ></td> </tr> </table></td> <td width="44%" align="center" background="../images/list_bottm_bg.gif"> <table width="307" border="0" cellspacing="0" cellpadding="0"> <form name="form2" method="post" action="?"> <tr> <td width="236"><input name="key" type="text" class="list-s-bg" id="key" onFocus="this.className='list-s-bg1'" onBlur="this.className='list-s-bg'" value="<?php echo $_REQUEST["key"];?>"></td> <td width="71"><input type="image" name="imageField" src="../images/list_s_bottm.gif"></td> </tr> </form> </table> </td> <td width="19%" background="../images/list_bottm_bg.gif"><a href="javascript:history.back(-1)"><img src="../images/list_bottm5.gif" style="max-width:90%" style="max-width:90%" border="0" onMouseOver="this.src='../images/list_bottm5h.gif'" onMouseOut="this.src='../images/list_bottm5.gif'" alt="PHP 中的“新”字" ></a></td> </tr></table><script>function DelGood(x){ if(confirm('确认删除选择的记录?')) { window.location.href = "List_Del.php?operation=del&wz=<?php $_REQUEST["wz"]?>&checkbox=" + x; }}</script></body></html>
问题在 点添加的时候 报数据无效代码如下
<table width="102%" border="0" cellspacing="0" cellpadding="0"><form name="form1" method="post" action="List_Save.php" enctype="multipart/form-data"> <tr> <td width="108" class="list black"> </td> <td width="891" class="list black"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="86%" align="center" class="black">信息添加</td> <td width="14%"><a href="javascript:history.back(-1)"><img src="../images/list_add3.gif" style="max-width:90%" style="max-width:90%" onMouseOver="this.src='../images/list_add4.gif'" onMouseOut="this.src='../images/list_add3.gif'" border="0"/ alt="PHP 中的“新”字" ></a></td> </tr> </table></td> </tr> <tr> <td height="28" align="center" class="list-add1">标题:</td> <td class="list-add1 pl8"><input type="text" name="title" size="50" /> <select name="wz" id="wz"> <option value="<?php echo $_REQUEST["wz"] ?>" selected="selected"><?php echo $_REQUEST["wz"] ?></option> </select></td> </tr> <tr> <td height="28" align="center" class="list-add1">副标题:</td> <td class="list-add1 pl8"><input type="text" name="title2" size="50" /></td> </tr> <tr> <td height="28" align="center" class="list-add1">作者:</td> <td class="list-add1 pl8"><input name="zz" type="text" id="zz" size="30" /></td> </tr> <tr> <td height="28" align="center" class="list-add1">来源:</td> <td class="list-add1 pl8"><input name="ly" type="text" id="ly" size="50" /></td> </tr> <tr> <td height="28" align="center" class="list-add1">日期:</td> <td class="list-add1 pl8"><IFRAME frameBorder=0 id=popFrame name=popFrame scrolling=no src="../calendar.htm" style="BORDER-BOTTOM: 2px ridge; BORDER-LEFT: 2px ridge; BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; POSITION: absolute; VISIBILITY: hidden; Z-INDEX: 65535"></IFRAME> <input id="dc1" name="postdate" type="text" size="18" onfocus="this.className='job_Bladeinput2'" onblur="this.className='job_Bladeinput'" readOnly/> <input type="button" class="job_submit" onClick="popFrame.fPopCalendar('dc1','dc1',event);" value="选择日期"/> </td> </tr> <tr> <td height="28" align="center" class="list-add1">图片:</td> <td class="list-add1 pl8"><input type="file" name="file" size="35" /> 图片是否显示:<input name="picshow" type="checkbox" id="picshow" value="1" checked="checked" /></td> </tr> <tr > <td height="28" align="center" class="list-add1">缩略图:</td> <td class="list-add1 pl8"> <input type="file" name="file2" size="35" /></td> </tr> <tr > <td height="28" align="center" class="list-add1">操作:</td> <td class="list-add1"> 推荐: <input name="tj" type="checkbox" value="1" /> 幻灯: <input type="checkbox" name="hd" value="1" /> 头条:<input name="tt" type="checkbox" id="tt" value="1" /> New图标:<input name="new" type="checkbox" id="new" value="1" /></td> </tr> <tr > <td align="center" class="list-add1">内容:</td> <td class="list-add1"><IFRAME ID="eWebEditor1" SRC="../eWebEditor/ewebeditor.php?id=content&style=s_blue" FRAMEBORDER="0" SCROLLING="no" WIDTH="100%" HEIGHT="360"></IFRAME><input name="content" type="hidden" id="content"></td></tr> <tr > <td height="40" align="center" class="list-add1"> </td> <td align="center" class="list-add1"><input type="image" name="imageField" src="../images/list_add1.gif" onMouseOver="this.src='../images/list_add2.gif'" onMouseOut="this.src='../images/list_add1.gif'"/><input type="hidden" name="operation" value="add"></td> </tr> </form> </table>
为什么第一次可以到list.php有用 再传到add页面 就是无效数据 把“新”字删了 就好了
诡异
如果用url传递中文的,任何时候都记得先urlencode,否则出错有的你哭
因为这牵涉到 浏览器识别、浏览器传递、服务器识别、服务器传递给php这4个层面,如果这4个环节任意一个编码不对,都会导致无法识别参数。
改变为
"
其他地方同样对待,也就是说使用x.php?x=X这种格式传递时,一定要保证X的值是urlencode编码过的,特别是中文。
如果用url传递中文的,任何时候都记得先urlencode,否则出错有的你哭
因为这牵涉到 浏览器识别、浏览器传递、服务器识别、服务器传递给php这4个层面,如果这4个环节任意一个编码不对,都会导致无法识别参数。
改变为
"
其他地方同样对待,也就是说使用x.php?x=X这种格式传递时,一定要保证X的值是urlencode编码过的,特别是中文。
谢谢 这个方法我刚我试了 还是没用