The Daily Click ::. Forums ::. Non-Klik Coding Help ::. PHP coding
 

Post Reply  Post Oekaki 
 

Posted By Message

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
17th October, 2011 at 15:31:08 -

Hi,

I am trying to create a comment box using PHP code and a mySQL Database following this tutorial:

http://www.youtube.com/watch?v=CS45YAqCgX8

I have completed the whole video and when I view my website I get the following error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/whenther/public_html/connect.php on line 3

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'whenther'@'localhost' (using password: NO) in /home/whenther/public_html/connect.php on line 4

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/whenther/public_html/connect.php on line 4


Can anybody help me out here? I'm not sure where I would have made my mistake.

Cheers!

Edited by Chris Burrows

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
17th October, 2011 at 16:59:20 -

The mistake is on lines 3 and 4.

Make sure you have your database setup correctly.

 
n/a

Fordom

Nordanrikets konung

Registered
  12/02/2009
Points
  190

VIP Member
17th October, 2011 at 19:58:21 -


Originally Posted by . : UrbanMonk : .
The mistake is on lines 3 and 4.

Make sure you have your database setup correctly.


No shit,

 
This forum is full of trolls and disinfo agents.

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
17th October, 2011 at 20:35:53 -


Originally Posted by Fordom

Originally Posted by . : UrbanMonk : .
The mistake is on lines 3 and 4.

Make sure you have your database setup correctly.


No shit,



First of all those are not errors, they are warnings. most "errors" in php are fatal and would kill the script unless handled.

Learn to use warning/error messages. They tell you everything you need.

Warnings in file connect.php on lines 3, 4, and 4 again.
Describes the first 2 warnings as database access denied. therefore you provided the wrong user information and password to be passed to the database, or your database is not set up correctly for the user information you provided.
The third Warning is just informing you that because of the other warnings, it couldnt connect to the database.

At this point no one can really help you without access to your website, code, and database.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
17th October, 2011 at 20:45:20 -

btw, that was one of the worst tutorials i have ever watched.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
18th October, 2011 at 01:16:18 -


It is the only one I could find for coding a message box from scratch. I am new to PHP. But yeah it is terrible!

Ok so it has a problem connecting to my database. I may not have set it up properly.

Here is the code for connect.php, the script that connects to my database:

<?php

mysql_connect("localhost","root","");
mysql_select_db("comment");

?>



and here is my website code that calls that script:


<?php
require('connect.php');
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['sumbit'];

if($submit)
{

if($name&&$comment)
{
$query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')");
}
else
{
echo "Please fill out all the fields.";
}

}
?>


this is the url if to see the errors in action: http://www.whenthereisnoroominhellthedeadwalktheearth.com/test.php

i am pretty sure the local host part i made bold is a problem.

if anybody who has expereince in this field would like to check my database to see if it has been set up correctly I am happy to give you access to my website.

 
n/a

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
18th October, 2011 at 02:09:07 -

Shouldn't root have a password?

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
18th October, 2011 at 02:34:11 -

Pretty sure it doesn't need one.

Part of the error message includes: (using password: NO) which suggests that I'm not using one, as opposed to an incorrect one.

Go to: http://www.whenthereisnoroominhellthedeadwalktheearth.com/test.php for the full error message.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
18th October, 2011 at 02:57:09 -

actually i've got it connecting now. i hadn't made a user or password for my database. but now it just doesn't seem to be sending the comments to my database...

 
n/a

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
18th October, 2011 at 04:20:31 -


Originally Posted by Chris Burrows
Pretty sure it doesn't need one.

Part of the error message includes: (using password: NO) which suggests that I'm not using one, as opposed to an incorrect one.

Well that's because you aren't using one. "" isn't a password, so that counts as not using a password just as much as not having included the parameter at all. Since it said that you weren't using a password, the only possibilities I can think of for the source of that error are either you not using a password for root when you need one (the super likeliest) or there not being a root user at all (not likely).

That is to say that it telling you that you aren't using a password is telling you just that, that you didn't give it a password. That is different from telling you that you're using the wrong password (in which case it would have said "using password: YES".)

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
18th October, 2011 at 04:29:15 -

id should not be in your insert query. id is a key and is autoincrement.

"INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')"

should be

"INSERT INTO comment (name,comment) VALUES ('$name','$comment')"

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
18th October, 2011 at 04:30:14 -

also id is a keyword in sql so when using it you need to surround it with graves `id`. iirc anyways.

 
n/a

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
18th October, 2011 at 16:37:22 -


Originally Posted by The Cecilizer
also id is a keyword in sql so when using it you need to surround it with graves `id`. iirc anyways.

I usually call it something like c_id for comments, so *_id, where * is a letter representing the content.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
19th October, 2011 at 05:52:41 -


Hello again,

Ok so I've been up for 2 days straight working on this

http://www.whenthereisnoroominhellthedeadwalktheearth.com/test.php

It is complete except for 1 thing: When you click "Post Comment" it takes you to an ugly page telling you that you have posted a comment. I want it to just refresh the current page and display the new comment, and empty the text fields.

Anybody know how to do this?

Thank you again!

Chris




 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
19th October, 2011 at 07:53:10 -

Never mind. Fixed it. Thanks anyway though everybody

 
n/a
   

Post Reply



 



Advertisement

Worth A Click