<html>
<head>
<title>留言本</title>
</head>
<body>
<?php
if($_post['submit'])
{
$name=$_post['name'];
$time=getdate();
$txt=$_post['txt'];
$conn=mysql_connect("localhost","root","123")or die ("can't connect to mysql");
$qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
//$qurry = "select *from tb";
$result= mysql_db_query("test",$qurry);
//$row=mysql_fetch_row($result);
//print_r($row);
}
else
{
?>
<form action="<?php echo$PATH_INFO;?>" method="post" >
姓名:<input type="text" name="name"><br>
留言:<textarea name="txt" rows="10" cols="50">
</textarea>
<input type="reset" value="清除">
<input type="submit" name="submit" value="留言提交">
</form>
<?php
}
?>
</body>
</html>上面为什么我点"留言提交" 这个按钮 数据库没反应?是POST没传值还是 我那边写错了?
刚学PHP 希望高手指正!
然后在mysql执行看行不行
Create table (
id int not null auto_increment,
name char(8) not null,
time datetime not null,
txt varchar(5000) not null,
primary key (id)
)数据库结构这样
运行时没报错!
id int not null auto_increment,
name char(8) not null,
time datetime not null,
txt varchar(5000) not null,
primary key (id)
)
数据库字段为 not null 不允许为空另外在数据库中 手动执行下 insert into tb(name,time,txt) values ('Discounts','2009-10-26 00:00:00','http://www.discountsinchina.com');
我查了一下 有好几种写法
1.<form action="<?php echo$PATH_INFO;?>" method="post" >
2.<form action="<?php echo $_SERVER["PATH_SELF"];?>" method="post" >
3.<form action="<?php echo $PATH_SELF;?>" method="post" >
哎!以前是学ASP.NET。现在搞PHP了
改成<form method="post" >
或则
<form action='' method='POST'> 也可以传到本页!
<head>
<title>留言本</title>
</head>
<body>
<?php
if($_POST['submit'])
{
$name=$_POST['name'];
$time=date("Y-m-d H:i:s");
$txt=$_POST['txt'];
$conn=mysql_connect("localhost","root","123")or die ("can't connect to mysql");
$qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
//$qurry = "select *from tb";
$result= mysql_db_query("test",$qurry);
//$row=mysql_fetch_row($result);
//print_r($row);
}
else
{
?>
<form action="<?php echo $PATH_INFO;?>" method="post" >
姓名:<input type="text" name="name"><br>
留言:<textarea name="txt" rows="10" cols="50">
</textarea>
<input type="reset" value="清除">
<input type="submit" name="submit" value="留言提交">
</form>
<?php
}
?>
</body>
</html>
{
$name=$_POST['name'];
$time=date("Y-m-d H:i:s");
$txt=$_POST['txt'];
$conn=mysql_connect("localhost","root","123")or die (mysql_error()."不能连接mysql");
$qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
//$qurry = "select *from tb";
$result= mysql_db_query("test",$qurry) or die (mysql_error()."不能连接mysql");
//$row=mysql_fetch_row($result);
//print_r($row);
}
else
{
?>
再问一下 $PATH_INFO 这应该是个链接赋给这个变量了吧 你有这个连接的页面吗?!是本页?还是...
提交的值对不对把 $_POST打印出来就看到了~~~~~~~
var_dump($_POST);