[初学者]写了一个漏洞百出的新闻发布页面,错误百出,求帮助 本帖最后由 xuzuning 于 2011-04-18 16:07:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 include 'newsql.php';//加上引号if ($_SESSION ['user']) {//同上echo "{$_SESSION['user']}";//同上然后把错误贴出来看 +$res = mysql_query ($news_sql);//括号里不要加引号 感谢1楼和3楼的指点,按照各位的提示,现在报错为弹出窗口“erro”注释掉之后没有显示SEESION,显示发表失败 判断一个值是否设置,使用isset()或empty(),不要直接使用if().如:if (isset($_SESSION ['user'])) { //code}if (isset($_POST ["submit"])) {//找错误的时候不要把'@'这样的符号加前面 //code}//..... 最基本的逻辑你都那个啥...你看看数下来第7行,else后面那个花括号被你吃了?还有就是假如$_SESSION['use']存在那反而不存进数据库了?什么逻辑? <?phpsession_start ();include 'newsql.php';if ($_SESSION ['user']) { echo "{$_SESSION['user']}";} else{ echo "SEESION调用失败";}if ($_POST ["submit"]) { $author = $_POST ["author"]; $department = $_POST ["department"]; $title = $_POST ["title"]; $content = $_POST["content"]; $date = date ( "y-m-d H:i" ); $news_sql = "INSERT INTO news(title,date,author,department,content) VALUES('$title','$date','$author','$department','$content')"; $res = mysql_query ($news_sql); if ($res) { echo "发表成功"; } else { echo "发表失败!"; }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>新闻发布</title><style type="text/css"><!--body { font-size: 12px; background: #FAFCFF;}</style></head><body><table width="681" border="0" cellspacing="0" cellpadding="0" align="center"> <form action="" method="post" name="message"> <tr> <td height="25" colspan="2" align="center"><strong>新闻发布</strong></td> </tr> <tr> <td width="109" height="25" align="right">标题: </td> <td width="572" height="25"><input name="title" type="text" class="input" id="title" /> <font color="#000000">*</font>(<font color="#ff6600">*</font>为必填项)</td></tr><tr> <td height="25" align="right">department: </td> <td height="25"><input name="部门" type="text" class="input" id="department" /></td></tr><tr> <td height="25" align="right">作者 </td> <td height="25"><input name="author" type="text" class="input" id="author" size="30" /></td></tr><tr> <td height="25" align="right">内容: </td> <td height="25"><label> <textarea name="content" cols="70" rows="15" class="input" id="content"></textarea> <font color="#000000">*</font></td></tr><tr> <td height="25"> </td> <td height="25"><label> <input name="submit" type="submit" class="botton" id="submit" value="发表留言" /> <input name="reset" type="reset" class="botton" value="重新填写" id="reset" /> <input name="submit" type="hidden" id="submit" value="submit" /></td></tr></form></table></body></html> 提示Notice: Undefined index: user in G:\PHPnow-1.5.6\htdocs\new\news.php on line 4SEESION调用失败Notice: Undefined index: submit in G:\PHPnow-1.5.6\htdocs\new\news.php on line 9 有关php的错误 setcookie与_COOKIE[]的执行顺序 初学者提问 高分 请教一个问题关于php并发的问题?这是叫并发吗? 非技术的php问题 int_set设置无效? 哪位提供一些php的技术群号过来? 如果浏览器关闭,脚本中的指令还会执行完吗? 菜鸟问题,请指教,在线急!!! 各位大侠,请问那里有免费支持php的空间啊? 火狐浏览器为什么不能用js调用xml 写了一个留言本,为什么不显示内容
include 'newsql.php';//加上引号
if ($_SESSION ['user']) {//同上
echo "{$_SESSION['user']}";//同上然后把错误贴出来看
$res = mysql_query ($news_sql);//括号里不要加引号
//code
}
if (isset($_POST ["submit"])) {//找错误的时候不要把'@'这样的符号加前面
//code
}
//.....
你看看数下来第7行,else后面那个花括号被你吃了?还有就是假如$_SESSION['use']存在那反而不存进数据库了?什么逻辑?
<?php
session_start ();
include 'newsql.php';
if ($_SESSION ['user']) {
echo "{$_SESSION['user']}";
} else{
echo "SEESION调用失败";
}
if ($_POST ["submit"]) {
$author = $_POST ["author"];
$department = $_POST ["department"];
$title = $_POST ["title"];
$content = $_POST["content"];
$date = date ( "y-m-d H:i" );
$news_sql = "INSERT INTO news(title,date,author,department,content) VALUES('$title','$date','$author','$department','$content')";
$res = mysql_query ($news_sql);
if ($res) {
echo "发表成功";
} else {
echo "发表失败!";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻发布</title>
<style type="text/css">
<!--
body {
font-size: 12px;
background: #FAFCFF;
}
</style>
</head>
<body>
<table width="681" border="0" cellspacing="0" cellpadding="0"
align="center">
<form action="" method="post" name="message">
<tr>
<td height="25" colspan="2" align="center"><strong>新闻发布</strong></td>
</tr>
<tr>
<td width="109" height="25" align="right">标题: </td>
<td width="572" height="25"><input name="title" type="text" class="input" id="title" />
<font color="#000000">*</font>(<font color="#ff6600">*</font>为必填项)
</td>
</tr><tr>
<td height="25" align="right">department: </td>
<td height="25"><input name="部门" type="text" class="input" id="department" /></td>
</tr>
<tr>
<td height="25" align="right">作者 </td>
<td height="25"><input name="author" type="text" class="input" id="author" size="30" /></td>
</tr><tr>
<td height="25" align="right">内容: </td>
<td height="25"><label> <textarea name="content" cols="70" rows="15" class="input" id="content"></textarea>
<font color="#000000">*</font></td>
</tr>
<tr>
<td height="25"> </td>
<td height="25"><label> <input name="submit" type="submit" class="botton" id="submit" value="发表留言" />
<input name="reset" type="reset" class="botton" value="重新填写" id="reset" />
<input name="submit" type="hidden" id="submit" value="submit" /></td>
</tr>
</form>
</table>
</body>
</html>
SEESION调用失败
Notice: Undefined index: submit in G:\PHPnow-1.5.6\htdocs\new\news.php on line 9