<?php
$mysql_db=mysql_connect("localhost","root","372110");
mysql_select_db("test",$mysql_db);
if($submit)
{
if(!empty($name) && !empty($title) && !empty($coment))
{
$time=date("y-m-d H:i:s");
$ip=$REMOTE_ADDR;
$sql="INSERT into guestbook(name,email,homepage,dity,country,title,comment,time,ip)
VALUES('$name','$email','$homepage','$dity','$country','$title','$coment','$time','$ip')";
$sql_result=mysql_query($sql);
}
else
{
print("<center>请您将带*的内容填齐。<br>");
print("<a href=\"guest.php3\">返回重填</a></center>");
exit();
}
}
?>
Notice: Undefined variable: submit in D:\phpnow\htdocs\web\title.php on line 6
$mysql_db=mysql_connect("localhost","root","372110");
mysql_select_db("test",$mysql_db);
if($submit)
{
if(!empty($name) && !empty($title) && !empty($coment))
{
$time=date("y-m-d H:i:s");
$ip=$REMOTE_ADDR;
$sql="INSERT into guestbook(name,email,homepage,dity,country,title,comment,time,ip)
VALUES('$name','$email','$homepage','$dity','$country','$title','$coment','$time','$ip')";
$sql_result=mysql_query($sql);
}
else
{
print("<center>请您将带*的内容填齐。<br>");
print("<a href=\"guest.php3\">返回重填</a></center>");
exit();
}
}
?>
Notice: Undefined variable: submit in D:\phpnow\htdocs\web\title.php on line 6
$submit程序的开始就有了。
这个页面有无继承其它的页面?
<form ...>
<input name="submit">
<input name="name">
<input name="title">
<input name="coment">
</form>
然后还要看你的php.ini配置,有没有打开变量注册,如果没有的话,PHP中要用$_REQUEST['submit']、$_REQUEST['name']、$_REQUEST['title']、$_REQUEST['coment']来获取。
另外,$ip=$REMOTE_ADDR;也不好,应该是$ip=$_SERVER['REMOTE_ADDR'];
最后,你的数据入库前最好用mysql_escape_string这个函数包装一下,否则容易引起注入。
<input name="submit">
<input name="name">
<input name="title">
<input name="coment">
</form>
这个在登录页面有。
<form ...>
<input name="submit">
<input name="name">
<input name="title">
<input name="coment">
</form>
<?php
function post($name){
$name = isset($_POST[$name]) ? $_POST[$name] : null;
}
$mysql_db=mysql_connect("localhost","root","372110");
mysql_select_db("test",$mysql_db);
if($_SERVER['REQUEST_METHOD']=='POST'){
if(!empty(post('name')) && !empty(post('title')) && !empty(post('coment'))){
$ip=$REMOTE_ADDR;
$sql="INSERT into guestbook(name,email,homepage,dity,country,title,comment,time,ip)
VALUES('".post('name')."','".post('email')."','".post('homepage')."','".post('dity')."','".post('country')."','".post('title')."','".post('coment')."',NOW(),'".post('ip')."')";
$sql_result=mysql_query($sql);
}else{
print("<center>请您将带*的内容填齐。<br>");
print("<a href=\"guest.php3\">返回重填</a></center>");
exit();
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>我的留言簿</title>
</head><body style="font-family:arial; font-size:11pt; color:rgb(0,0,128)">
<form method="post" action="title.php">
<div align="center">
<center>
<table border="0" cellpadding="0" width="500">
<tr>
<td width="100%" colspan="2" bgcolor="#ebb38d"><center><p>
<font face="楷体_gb2312" color="#00100ff">
<big><big><strong>我的留言簿</strong></big></big></font></p></center>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#b1f3bb">姓名:*</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="name" size="20" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#b1f3bb">E-Mail:</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="email" size="45" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#b1f3bb">主页:</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="homepage" size="45" value="http://" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#b1f3bb">城市:</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="city" size="12" value="北京" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#b1f3bb">国家:</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="country" size="12" value="中国" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#bif3bb">留言主题:*</td>
<td width="400" bgcolor="#b1f3bb" align="left">
<input type="text" name="title" size="50" />
</td>
</tr>
<tr>
<td width="100" bgcolor="#bif3bb">您的留言:*</td>
<td width="400" bgcolor="#bif3bb" align="left">
<textarea rows="6" name="comment" cols="50"></textarea>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#b1f3bb" colspan="2"><center><p>
<input type="submit" name="submit" value="提交留言" />
<input type="reset" name="reset" value="摘除重写" /></p></center>
</td>
</tr>
</table>
</center>
</div>
</form>
<center><a href="title.php">浏览留言</a></center>
</body>
</html>
$mysql_db=mysql_connect("localhost","root","372110");
mysql_select_db("test",$mysql_db);
if($submit)
{
if(!empty($name) && !empty($title) && !empty($coment))
{
$time=date("y-m-d H:i:s");
$ip=$_SERVER['REMOTE_ADDR'];
$sql="INSERT into guestbook(name,email,homepage,dity,country,title,comment,time,ip)
VALUES('$name','$email','$homepage','$dity','$country','$title','$coment','$time','$ip')";
$sql_result=mysql_query($sql);
}
else
{
print("<center>请您将带*的内容填齐。<br>");
print("<a href=\"guest.php\">返回重填</a></center>");
exit();
}
}
?>
<!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=gb2312" />
<title>无标题文档</title>
</head><body style="font-family:Arial; font-size:11pt; color:rgb(0,0,128)">
<center><strong><font face="楷体_GB2312">
<big><big>我的留言簿</big></big></font></strong></center>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="500">
<tr>
<td bgcolor="#c9f797" width="20%" height="25">留言人姓名</td>
<td bgcolor="#c9f797" width="50%" height="25">留言标题</td>
<td bgcolor="#c9f797" width="30%" height="25">留言时间</td>
</tr>
<?php
$sql="SELECT * FROM guestbook";
$sql_result=mysql_query($sql);
//计算总的记录条数
$sum=mysql_num_rows($sql_result);
if(empty($offset))
{
$offset=0;
}
$sql="select id,name,title,time from guestbook order by time DESC LIMIT $offset,
10";
$sql_result=mysql_query($sql);
while($sql_row=mysql_fetch_array($sql_result))
{
print("<tr>");
print("<td bgcolor=\"#f9fbdb\"width=\"20%\">$sql_row[1]</td>");
print("<td bgcolor=\"#f9fbdb\"width=\"50%\"><a href=detail.php3?id=$sql_row[0]>$sql_now[2]</a></td>");
print("<td bgcolor=\"#f9fbdb\"width=\"30%\">$sql_row[3]</td>");
print("</tr>");
}
mysql_close();
?>
<?php
//使用分页技术
if($offset)//如果偏移量是0,则没有上一页的链接
{
$preoffset=$offset-10;
print("<a href=\"$php_SELF?offset=$preoffset\">上一页</a> \n");
}
//计算总共需要的页数
$page_cnt=ceil($sum/10);
//显示到所有页的链接
for($i=1;$i<=$page_cnt;$i++)
{
$page_offset=10*$i-10;
print("<a href=\"$php_SELF?offset=$page_offset\">$i</a> \n");
}
//检查是否是最后一页
if($page_cnt!=0 && (($offset+10)/10)!=$page_cnt)
{
$backoffset=$offset+10;
print("<a href=\"$php_SELF?offset=$backoffset\">下一页</a> \n");
}
?>
<p><center><a href="guest.php">我要留言</a></center></p>
</table>
</center>
</div>
</body>
</html>
$mysql_db=mysql_counect("localhost","root","372110")
mysql_select_db("test",$mysql_db);
$sql="SELECT * FROM guestbook where id=$id";
$sql_result=mysql_query($sql);
$sql_row=mysql_fetch_array($sql_result);
?>
<!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=gb2312" />
<title>我的留言簿</title>
</head><body style="font-family:arial; font-size:11pt; color:rgb(0,0,128)">
<div align="center"><center>
<table border="0" cellpadding="0" width="500">
<tr>
<td width="100%" bgcolor="#ebb38d"><p align="center">
<font face="楷体_gb2312" color="#00100ff">
<big><big><strong>我的留言簿</strong></big></big></font></p></td>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb"><br />
留言人姓名:<?print($sql_now["name"]);?></td>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb">E-Mail地址:
<? print("<a href=\"mailto:$sql_row[email]\">"); ?>
<? print(&sql_now["email"]); ?>
<? print("</a>"); ?>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb">主页:
<? print("<a href=\"$sql_row[homepage]\">");?>
<? print(&sql_now["homepage"]);?>
<? print("</a>");?>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb">来自:
<? print(&sql_now["country"]);?>
<? print("");?>
<? print(&sql_now["city"]);?>
<? print("");?>
<? print(&sql_now["ip"]);?>
<? print("");?>
</td>
<tr>
<td width="100%" bgcolor="#f9fbdb">时间:
<? print(&sql_now["time"]);?>
</td>
</tr>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb">留言:</td>
</tr>
<tr>
<td width="100%" bgcolor="#f9fbdb">
<? print(&sql_now["coment"]);?>
<? mysql_close();?>
</td>
</tr>
</table>
</center>
</div>
<center><a href="title.php">返回留言列表 </a></center>
</body>
</html>