我的代码如下:
<?php
$name=$_POST["name"];
$pass=$_POST["pass"];
$mycontent=$_POST["mycontent"];
$dat=$_POST["da"];$con=mysql_connect("localhost","java","java");
if(!$con)
{
die('can not connect '. mysql_error());
}mysql_select_db("test", $con);mysql_query("insert into content ('name','time','content') values('$name','$dat' ,'$mycontent') " );$result = mysql_query("SELECT * FROM content where 'name'='$name' ");while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr>";
echo "<td>" . $row['name'] ."发表于". "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "</tr>";
echo "</table>";
echo "<textarea >". $row['content']."</textarea>";
}
?> 而且整个页面是空白的,我觉得是没有插入到数据库中又取不到值导致的。
错误为:
(mysql_fetch_array():提供的参数不是一个有效的MySQL的结果资源 )****************************************
我觉得原因是:
我的数据$name,$dat,$mycontent没有插入到数据库中,所以SELECT * FROM content where 'name'='$name' 不是数据库已有的资源。
******************************************
确认了一下,数据库名和表名写的没有问题,列名也没有问题。
<?php
$name=$_POST["name"];
$pass=$_POST["pass"];
$mycontent=$_POST["mycontent"];
$dat=$_POST["da"];$con=mysql_connect("localhost","java","java");
if(!$con)
{
die('can not connect '. mysql_error());
}mysql_select_db("test", $con);mysql_query("insert into content ('name','time','content') values('$name','$dat' ,'$mycontent') " );$result = mysql_query("SELECT * FROM content where 'name'='$name' ");while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr>";
echo "<td>" . $row['name'] ."发表于". "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "</tr>";
echo "</table>";
echo "<textarea >". $row['content']."</textarea>";
}
?> 而且整个页面是空白的,我觉得是没有插入到数据库中又取不到值导致的。
错误为:
(mysql_fetch_array():提供的参数不是一个有效的MySQL的结果资源 )****************************************
我觉得原因是:
我的数据$name,$dat,$mycontent没有插入到数据库中,所以SELECT * FROM content where 'name'='$name' 不是数据库已有的资源。
******************************************
确认了一下,数据库名和表名写的没有问题,列名也没有问题。
mysql_query("insert into content ('name','time','content') values('$name','$dat' ,'$mycontent') " );
这个也是 数据库中的字段不要加引号OK?
if(!$con)
{
die('can not connect '. mysql_error());
}可以直接这样写mysql_connect("localhost","java","java") or die('can not connect '. mysql_error());
看看报什么错先,这种问题一般是你的SQL语句书写有问题引起的
是错误的SELECT * FROM content where `name`='$name'
这样才是正确的