即使脚本运行,也会收到错误

时间:2011-02-07 14:05:14

标签: php mysql

  

可能重复:
  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

我收到以下错误

  

警告:mysql_query()   [function.mysql-query]:访问被拒绝   对于用户'anticub1'@'localhost'(使用   密码:否)

     

警告:mysql_query()   [function.mysql-query]:指向的链接   服务器无法建立

警告:mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源

当我提交表单时,所有内容都会进入数据库,因此我不确定为什么会收到该错误...

<?php
$submit=$_POST['submit'];
$text=$_POST['text'];

if ($submit) {
  $connect = mysql_connect("localhost","anticub1_shout","root12")
    or die("could not connect");
  mysql_select_db("anticub1_shoutbox") or die("could not find the db");

  mysql_query("INSERT INTO comments VALUES ('','$text')");}

  $query = mysql_query("SELECT * FROM comments");

  while ($row = mysql_fetch_assoc($query)) {
    $post = $row["posts"];
    echo "$post"."<br>";
  }
?>

1 个答案:

答案 0 :(得分:0)

警告:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'anticub1'@'localhost' (using password: NO) 

您的示例脚本是否生成 NOT !因为你在那里提供了一个密码和另一个用户名。

$connect = mysql_connect("localhost","anticub1_shout","root12")

结论:您正在错误的地方搜索。搜索mysql_connect("localhost","anticub1")

的所有代码
相关问题