0

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

I am receiving the following errors

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

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

When I submit the form everything goes into the database so I am not sure why I am getting that error...

<?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>";
  }
?>
Community
  • 1
  • 1
  • 1
    Check the DB is on same server and username, password are correct – Shakti Singh Feb 07 '11 at 14:11
  • yes everything is correct when I submit the form information I am seeing it in the database – Jamie Frue Feb 07 '11 at 14:14
  • Please try to format your code more cleanly/consistently. It makes it really hard to read when your indentation isn't lined up and you don't stick to a particular brace style. Also, is there more of the code? Your `if` block isn't closed, so perhaps something after it is generating the error. And there are quite a few other problems with the code, such as the use of unsanitized user inputs directly in a query string. The echo line could also be simplified as `echo "$post
    ";`.
    – Lèse majesté Feb 07 '11 at 14:20
  • 1
    @Lèse majesté, actually the `if` block _is_ closed... look at the end of the `mysql_query` line, there's a `}`. Took me a moment to figure it out. – Andrew Feb 07 '11 at 14:33
  • @Andew: Ah, I see it now. That's why formatting is important for readability. – Lèse majesté Feb 07 '11 at 17:24

1 Answers1

0

The warning:

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

Is NOT produced by your example script! because you provide a password there and its an other username.

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

Conclusion: You are searching at the wrong place. Search trough all your code for mysql_connect("localhost","anticub1")

powtac
  • 40,542
  • 28
  • 115
  • 170