现在我做个HTML。action到一个PHP文件处理。但我点击发送就显示下载这个PHP文件,。是不是我PHP没配置好啊
我先做了个购物车的实验,是可以用的。
luyang.html
代码:
<html>
<head>
<title>...</title>
</head>
<body>
<form method="post" action="message.php">
<table align="center" width="90%">
<tr>
<td align="right" width="30%">邮箱:</td>
<td><input type="text" name="email" size="30"></td>
</tr>
<tr>
<td align="right">标题:</td>
<td><input type="text" name="title" size="80" /></td>
</tr>
<tr>
<td align="right">留言:</td>
<td><textarea name="content" cols="80" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="发表留言" /></td>
</tr>
</table>
</form>
</body>
</html>
message.php
代码:
<?php
$mysql_host='localhost';
$mysql_user='root';
$mysql_password='root';
$mysql_database='test';
mysql_connect($mysql_host,$mysql_user,$mysql_password) or die (mysql_error());
mysql_select_db($mysql_database) or die(mysql_error());
mysql_query("set names 'gbk'");
if (isset($_POST['email'])){
$email=addslashes($_POST['email']);
$title=$_POST['title'];
$content=$_POST['content'];
$ip=$_SERVER['REMOTE_ADDR'];
$sql="insert into messages values (null,'$email','$title','$content','$ip',now(),".floor(rand()*mysql_insert_id()).")";
mysql_query($sql) or die($sql.mysql_error());
}
$rowsPerPage=3;
$row=mysql_fetch_assoc(mysql_query("select count(*) as c from messages"));
$rows =$row['c'];
$pages=ceil($rows/$rowsPerPage);
$curPage=1;
if(isset($_REQUEST['curPage']))
$curPage=$_REQUEST['curPage'];
$sql ="select *from messages order by id desc"
."limit".($curPage-1)*$rowsPerPage.", $rowsPerPage";
$result=mysql_query($sql) or die(mysql_error());
while($row =mysql_fetch_assoc($result)){
echo"<table width=90% align=center cellpadding=1 cellspacing=1 bgcolor=blue>";
echo" <tr>";
echo" <td rowspan=2 width=25% bgcolor=white>";
echo" <li><font color=red></font>{$row['id']}";
echo" <li><font color=red></font>{$row['useremail']}";
echo" <li><font color=red></font>{$row['userip']}";
echo" <li><font color=red></font>{$row['mtime']}";
echo" <li><font color=red></font>{$row['pid']}";
echo" </td>";
echo" <td bgcolor=yellow><font color=red>标题:</font><a href=modifyMsg.php?id={$row['id']}>{$row['title']}</a></td>";
echo" </tr>";
echo" <tr>";
echo" <td bgcolor=white>{$row['content']}</td>";
echo" </tr>";
echo" </table>";
echo" <br>";
}
echo"<div align=center>";
for($i=1;$i<=$pages;$i++){
echo"<a href='message.php?curPage=$i'>$i</a> ";
}
echo"<form name=form1 action=message.php method=post>";
echo" <select name=curPage onchange='document.form1.submit();'>";
for ($i=1;$i<=$pages;$i++){
if($i==$curPage)
echo"<option selected>$i</option>";
else
echo"<option>$i</option>";
}
echo"</select>";
echo"</form>";
if($curPage>1){
echo"<a href='message.php?curPage=1'></a> ";
echo"<a href='message.php?curPage=".($curPage-1)."'>前页</a> ";
}
if($curPage<$pages){
echo"<a href='message.php?curPage=".($curPage+1)."'>后页</a> ";
echo"<a href='message.php?curPage=$pages'>末页</a> ";
}
echo"</div>";
?>
请大虾帮我看看。感击跳楼
我先做了个购物车的实验,是可以用的。
luyang.html
代码:
<html>
<head>
<title>...</title>
</head>
<body>
<form method="post" action="message.php">
<table align="center" width="90%">
<tr>
<td align="right" width="30%">邮箱:</td>
<td><input type="text" name="email" size="30"></td>
</tr>
<tr>
<td align="right">标题:</td>
<td><input type="text" name="title" size="80" /></td>
</tr>
<tr>
<td align="right">留言:</td>
<td><textarea name="content" cols="80" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="发表留言" /></td>
</tr>
</table>
</form>
</body>
</html>
message.php
代码:
<?php
$mysql_host='localhost';
$mysql_user='root';
$mysql_password='root';
$mysql_database='test';
mysql_connect($mysql_host,$mysql_user,$mysql_password) or die (mysql_error());
mysql_select_db($mysql_database) or die(mysql_error());
mysql_query("set names 'gbk'");
if (isset($_POST['email'])){
$email=addslashes($_POST['email']);
$title=$_POST['title'];
$content=$_POST['content'];
$ip=$_SERVER['REMOTE_ADDR'];
$sql="insert into messages values (null,'$email','$title','$content','$ip',now(),".floor(rand()*mysql_insert_id()).")";
mysql_query($sql) or die($sql.mysql_error());
}
$rowsPerPage=3;
$row=mysql_fetch_assoc(mysql_query("select count(*) as c from messages"));
$rows =$row['c'];
$pages=ceil($rows/$rowsPerPage);
$curPage=1;
if(isset($_REQUEST['curPage']))
$curPage=$_REQUEST['curPage'];
$sql ="select *from messages order by id desc"
."limit".($curPage-1)*$rowsPerPage.", $rowsPerPage";
$result=mysql_query($sql) or die(mysql_error());
while($row =mysql_fetch_assoc($result)){
echo"<table width=90% align=center cellpadding=1 cellspacing=1 bgcolor=blue>";
echo" <tr>";
echo" <td rowspan=2 width=25% bgcolor=white>";
echo" <li><font color=red></font>{$row['id']}";
echo" <li><font color=red></font>{$row['useremail']}";
echo" <li><font color=red></font>{$row['userip']}";
echo" <li><font color=red></font>{$row['mtime']}";
echo" <li><font color=red></font>{$row['pid']}";
echo" </td>";
echo" <td bgcolor=yellow><font color=red>标题:</font><a href=modifyMsg.php?id={$row['id']}>{$row['title']}</a></td>";
echo" </tr>";
echo" <tr>";
echo" <td bgcolor=white>{$row['content']}</td>";
echo" </tr>";
echo" </table>";
echo" <br>";
}
echo"<div align=center>";
for($i=1;$i<=$pages;$i++){
echo"<a href='message.php?curPage=$i'>$i</a> ";
}
echo"<form name=form1 action=message.php method=post>";
echo" <select name=curPage onchange='document.form1.submit();'>";
for ($i=1;$i<=$pages;$i++){
if($i==$curPage)
echo"<option selected>$i</option>";
else
echo"<option>$i</option>";
}
echo"</select>";
echo"</form>";
if($curPage>1){
echo"<a href='message.php?curPage=1'></a> ";
echo"<a href='message.php?curPage=".($curPage-1)."'>前页</a> ";
}
if($curPage<$pages){
echo"<a href='message.php?curPage=".($curPage+1)."'>后页</a> ";
echo"<a href='message.php?curPage=$pages'>末页</a> ";
}
echo"</div>";
?>
请大虾帮我看看。感击跳楼
phpinfo();
?>保存为test.php
然后放到服务器目录,在浏览器查看是否配置正确。
apache安装目录/conf/httpd.conf里添加下面两行,然后重启apacheAddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
echo 'hello world';
?>
你试试 <?php echo "hello" ?>看看
现在我的test数据库里这个messages表。。我创的不能用,你们谁会帮我写出来吧。好吗/?我搞了好久不弄不出来
$sql="insert into messages values (null,'$email','$title','$content','$ip',now(),".floor(rand()*mysql_insert_id()).")";
mysql_query($sql) or die($sql.mysql_error()); 造一个能把这个语句存起来的表这些都是对应插入的字段 Null ------> id (应该是对应id) $email ----->留言人的email $title ------->留言主题 $content ------>留言内容 $ip -------->留言人的ip now() ------->留言时间,这后面还有个不知是什么。。高手帮我看看噢噢噢
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`email` VARCHAR( 200 ) NOT NULL ,
`title` VARCHAR( 200 ) NOT NULL ,
`content` TEXT NOT NULL ,
`ip` VARCHAR( 20 ) NOT NULL ,
`created` INT NOT NULL
) ENGINE = MYISAM ;不知道你最后一个字段值到底是啥意思.
echo" <li> <font color=red> </font>{$row['useremail']}";
echo" <li> <font color=red> </font>{$row['userip']}";
echo" <li> <font color=red> </font>{$row['mtime']}";
echo" <li> <font color=red> </font>{$row['pid']}";
要对应这个的吧,那个名子。最后那个是什么意思我也不看不懂。没人懂么?晕。
create table messages (
id int(10) not null auto_increment primary key,
useremail varchar(50),
title varchar(50),
content text,
userip varchar(20),
created int not null,
pid int(10) , //这个是我猜的。乱弄的)
你给的这个没用。就是对应那个NOW()函数的、。。、无效
floor()是 舍去法取整
insert into messages values (null,'$email','$title','$content','$ip',now(),".floor(rand()*mysql_insert_id()).")唉....主鍵id換成自增長不就不用這么麻煩了每次都要寫id值...